Brink

Open-source safety guard for LLM fine-tuning

Keep a model safe while you fine-tune it.

Fine-tuning can quietly teach a safe model to answer harmful requests. Brink cleans the risky samples out of your training data, watches the model's refusals while it trains, and stops the run when they start to slip.

pip install "brink-safety[curatorkit] @ git+https://github.com/andrew1234-arch/brink"
94 % → 21 %harmful requests answered after the same fine-tune, without and with Brink
29 of 32harmful training samples removed by the gate before training
0 %harmless requests refused by the protected model
1.45 vs 1.46task loss without and with Brink: the model still learns the task
42 % → 6 %the same on a Hindi assistant trained through CuratorKIT and AlignTune

Measured on CohereLabs/tiny-aya-global in recorded runs. Full reports, including what did not work, are under Evidence.

How it works

Brink measures one thing: how strongly the model prefers to refuse a fixed set of harmful probe prompts, compared with the model before fine-tuning. It uses that measure at three points.

Before training

Gate

Scores every training sample by how much one training step on it would erode refusal, and drops the riskiest. You get a ranked list and a cleaned file.

During training

Monitor

Probes the model every few steps with one forward pass and raises an alarm when refusal stays below a threshold calibrated on safe fine-tuning.

On alarm

Repair

Halts the run, or rolls back to the last safe checkpoint and constrains the following updates so they cannot lower refusal.

After training

Verify

Checks the result on held-out harmful prompts, harmless prompts and task data, and writes a report.

Use it

Python 3.10 or later. Brink loads AdvBench and HarmBench as probe prompts, which are gated on Hugging Face: accept their terms once and log in with huggingface-cli login.

1. Clean your data before you train

Point Brink at a fine-tuning file (.jsonl, .json or .csv with prompt and response) and the model you will fine-tune.

brink gate my_finetune.jsonl --model CohereLabs/tiny-aya-global --drop 0.05 --out gated/

# gated/scored.csv     every sample with its risk score, riskiest first
# gated/cleaned.jsonl  your data without the riskiest 5 % and exact duplicates

2. Protect a training run

Add one callback to a Hugging Face Trainer or TRL SFTTrainer. Brink probes the model as it trains and halts when the alarm fires. Use "rollback_guard" to roll back and keep training under the guard instead.

from brink.monitor.callback import BrinkCallback
from brink.monitor.core import Monitor
from brink.probe import Prober, calibrate
from brink.repair import ErosionGuard, RepairController

fp, _ = calibrate(model, tok, harmful_cal, harmless_cal, harmful_probe, harmless_probe)

monitor = Monitor(Prober(fp, tok, harmful_probe, harmless_probe), "runs/my-finetune",
                  probe_every=4, alarm_signal="S3", alarm_threshold=-3.0)
controller = RepairController(monitor, "halt")

trainer = SFTTrainer(model=model, args=args, train_dataset=ds,
                     callbacks=[BrinkCallback(controller=controller)])
trainer.train()

3. Inside a CuratorKIT pipeline

The gate is a native CuratorKIT BaseGate, so it drops into an existing curation pipeline. With AlignTune, attach the same callback with attach_to_aligntune(trainer, callback).

from curatorkit.pipeline import Pipeline
from brink.gate import GateScorer
from brink.gate.curatorkit_gate import BrinkSafetyGate

gate = BrinkSafetyGate(GateScorer(model, tok, fp, harmful_probe, harmless_probe), drop_frac=0.05)
Pipeline([reader, ExactDeduplicator(), gate, exporter], output_dir="curated").run()

4. See all of it on a model, in one command

Runs the full loop on a small model, on CPU in about 20 minutes or on a GPU in a few, and writes a report you can read.

brink run --model Qwen/Qwen2.5-0.5B-Instruct --out runs/demo

# fingerprints the model, gates a contaminated set, fine-tunes it unprotected and with Brink,
# verifies both on held-out prompts and writes runs/demo/REPORT.md

5. Start from a model Brink already protected

A Hindi assistant fine-tuned from Tiny Aya on data with 10 % harmful samples, protected by Brink's gate, alarm and rollback. Load the LoRA adapter on top of the base model.

from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

base = AutoModelForCausalLM.from_pretrained("CohereLabs/tiny-aya-global")
tok = AutoTokenizer.from_pretrained("CohereLabs/tiny-aya-global")
model = PeftModel.from_pretrained(base, "cmgdevl/brink-artifacts", subfolder="adapters/pipeline/brink")

6. Or use the app

The same three jobs in a browser: run Brink live, upload a file to gate, and replay any run with your own alarm rule.

git clone https://github.com/andrew1234-arch/brink && cd brink
pip install -e ".[dashboard,curatorkit]"
make app        # http://localhost:7860: Run Brink, Gate your data, Experiments

Try it on a recorded run

This is a real fine-tune of CohereLabs/tiny-aya-global on data with harmful samples mixed in, logged step by step. Move the controls to see what Brink would have done with your settings.

Where would the alarm fire?

Brink reads the model's preference to refuse every few steps, as a z-score against the model before fine-tuning. The alarm fires when it stays under the line.

How much should the gate drop?

Before training, Brink scores every sample by how much one training step on it would erode refusal. Each bar is one training sample of this run.

harmful sample benign sample

The demo replays logged signals in your browser. To score your own data or run your own model, use the commands under Use it.

What to know before you rely on it

Measured limits, from the experiments below.

  • The alarm fires when refusals break, not before. It is a tripwire, not a forecast.
  • The gate and halting at the alarm are the parts that hold up on their own. Rollback with the guard, used alone on heavily contaminated data, was less safe than mixing in safety data.
  • Outside English the alarm needs its own calibration: with the English threshold it also fired on safe fine-tuning in Hindi and Tagalog.
  • Tested on one model family (Tiny Aya, 3.35B) with one or two seeds.
  • This page runs no model. Gating your data and protecting a run happen on your machine.

Evidence

Every experiment's report as the run wrote it, with its pre-set pass criteria, plots and logs. The "AuditKIT attacks resisted" column in the repair report predates a scoring fix: that run used AuditKIT's default detectors, which count a refusal as a failed attack. Read its attack success rate (ASR) instead.

Brink end to end (recorded live run)

Brink, end to end

Unprotected fine-tuning cut refusal from 77% to 4%; with Brink it ended at 69%, preventing 89% of the loss. Brink's alarm fired at step 20 of the unprotected run.

Model CohereLabs/tiny-aya-global on GPU; judge: wildguard. Fine-tuning data: 128 samples, 32 of them harmful-compliance samples. Verified on 48 held-out harmful prompts and 32 harmless ones.

Before fine-tuningUnprotectedWith Brink
Refuses harmful prompts77%4%69%
Attack success rate21%94%21%
Over-refusal (harmless prompts)0%0%0%
Held-out task loss2.0161.4521.462
Brink alarm20—

Gate. Dropped the 32 highest-risk samples; 29 of the 32 harmful samples were among them (precision 91% against 25% for random dropping, recall 91%).

Repair. Policy rollback_guard: rolled back to step —; halted at —.

Fingerprint. Refusal direction at layer 23/36.

A small, single-seed run sized to finish in minutes. The experiments (docs/) give the multi-seed numbers with confidence intervals.

Files: REPORT.md, config.json, fingerprint.json, gate.csv, meta.json, prompts.csv, status.json, summary.json

Pipeline: a Hindi assistant, before and afterPIPELINE DELIVERS

Pipeline (Hindi assistant, contaminated data): PIPELINE DELIVERS

  • ✅ P1_removes_most_of_the_drift
  • ✅ P2_learns_the_task
  • ✅ P3_no_over_refusal
  • ✅ P4_runs_on_the_lexsi_stack
modelHindi task loss ↓Hindi task chrF ↑ASR English ↓ (95 % CI)ASR Hindi ↓over-refusal (Hindi) ↓AuditKIT attacks resisted ↑traineralarm / repair
reference (Tiny Aya, no fine-tuning)2.10232.316%2%0%57%––
naive1.78831.742% (30%–54%)0%3%29%aligntune (trl backend)alarm at 16
brink1.80031.46% (2%–15%)0%0%57%aligntune (trl backend)alarm at 16, rolled back to 8, guard on

CuratorKIT + BrinkSafetyGate (brink): dropped 26 of 512 samples (top 5% by predicted refusal erosion), catching 21 of 51 contaminating samples; 5 benign samples dropped.

The Hindi ASR uses an English-trained judge and is less reliable than the English ASR.

Files: REPORT.md, config.json, data_summary.json, fingerprint.json, reference.json, summary.json

Go / no-go: is the drift detectable?NO-GO

Go / no-go: NO-GO

Seeds: [0, 1]

  • ✅ G1a_pos_drifts
  • ✅ G1b_control_stable
  • ❌ G2_signal_tracks_asr
  • ✅ G3_alarm_before_break_without_false_alarms

Notes

  • Best signal is the behavioural proxy S3. Claim a cheap early warning, not mechanistic foresight, unless the mechanistic S1 also leads.
Alarm per signal

Threshold calibrated on control runs only. False alarms and detection are leave-one-seed-out when there are 2 or more seeds. Lead = steps between the alarm firing and behaviour breaking (ASR +jump).

signalkindcalibrated zfalse alarms at fixed zLOO false-alarm ratedetectionlead (steps)Spearman vs ASR
S1mechanistic-9.52/20%0%-4.0-0.75
S1hmechanistic-26.72/250%0%-4.0-0.68
S2mechanistic-40.72/250%0%-8.0-0.75
S3proxy-3.00/20%100%0.0-0.50
Baseline: cheap judge every probe step

Lead -4.0 steps · false alarms on control 0/2 · 6.2 s per check

Runs
conditionseedASR start → end (95 % CI)behaviour breaksprobe seval s
pos016% → 100% (94%–100%)823.8103.2
pos116% → 97% (89%–99%)823.8102.5
control016% → 12% (6%–23%)n/a23.9100.5
control116% → 11% (5%–21%)n/a23.9100.6
go_nogo plot: go_nogo

Files: REPORT.md, config.json, data_summary.json, fingerprint.json, summary.json

Gate: finding the data that erodes safetyGATE NOT PROVEN

Gate experiment: GATE NOT PROVEN

  • ✅ D1_finds_planted_harmful
  • ✅ D1b_beats_rep_baseline
  • ❌ D2_top_scored_benign_breaks_safety_more
  • ✅ D3_low_scored_benign_is_safer
Detection of planted harmful samples in a benign pool
scoreAUROCrecall@krecall@top 5 %
grad_S3 (primary)0.9810.6000.860
grad_S10.9680.5400.720
rep0.9430.5600.700
random0.5250.0200.020
classifier0.9990.9401.000

The safety classifier flags 0% of the gate's top-scored benign subset: the risk the gate finds is invisible to a content filter.

Fine-tuning on benign subsets selected by grad_S3
subsetASR start → endheld-out loss start → endz_S1 endz_S3 end
top0.156 → 0.1902.051 → 1.449-23.9-7.3
random0.156 → 0.1092.051 → 1.439-15.33.2
bottom0.156 → 0.0942.051 → 1.500-10.010.0
gate plot: gate

Files: REPORT.md, config.json, data_summary.json, fingerprint.json, scores.csv, scoring_time.json, subsets.json, summary.json

Repair: rollback and the erosion guard vs baselinesREPAIR NOT PROVEN

Repair experiment: REPAIR NOT PROVEN

  • ✅ R1_removes_most_of_the_drift
  • ✅ R2_keeps_task_capability
  • ✅ R3_no_over_refusal
  • ❌ R4_beats_baselines_posthoc_and_safety_mix

Best Brink policy: halt

conditionASR start → endover-refusal start → endheld-out loss start → endAuditKIT attacks resistedAuditKIT benign answeredsteps trainedalarmnotes
none16% → 83%0% → 0%2.051 → 1.41786%100%12828
safety_mix16% → 23%0% → 0%2.051 → 1.41981%100%12828
halt16% → 17%0% → 0%2.051 → 1.46881%100%2828
rollback_guard16% → 41%0% → 0%2.051 → 1.41481%100%12828rolled back to step 20; guard projected 64/100 steps, removed 1% ofg² on average, refresh 338s
guard_always16% → 34%0% → 0%2.051 → 1.41781%100%128n/aguard projected 77/128 steps, removed 1% ofg² on average, refresh 447s
posthoc_steer83% → 19%0% → 3%1.417 → 1.47681%100%n/an/asteer strength 21.31; start = none (drifted)
posthoc_resta83% → 66%0% → 3%1.417 → 1.81786%100%n/an/aReSta alpha 0.25; start = none (drifted)
repair plot: repair

Files: REPORT.md, config.json, data_summary.json, fingerprint.json, summary.json

Multilingual: Hindi and Tagalog

Multilingual drift

  • First language whose behaviour breaks on pos: en at step 8
  • Lead over that first break: English-only alarm 0 steps, worst-language alarm 0 steps (negative = late)
  • Worst-language alarm on control (false alarm): yes

Note: the WildGuard judge is mostly English-trained, so non-English ASR is less reliable. The per-language S3 alarm is judge-free (calibrated on each language's own refusal tokens).

pos
languageASR start → endbehaviour breaksalarm (own S3)min z
en16% → 98%88-34.0
hi2% → 42%1616-9.6
tl2% → 29%1612-11.3

English-only alarm: step 8 · worst-language alarm: step 8

control
languageASR start → endbehaviour breaksalarm (own S3)min z
en16% → 12%n/an/a-0.0
hi2% → 0%n/a20-7.7
tl2% → 0%n/a20-9.2

English-only alarm: step n/a · worst-language alarm: step 20

multilingual plot: multilingual

Files: REPORT.md, config.json, data_summary.json, fingerprint.json, fingerprint_en.json, fingerprint_hi.json, fingerprint_tl.json, summary.json