Safety guardrails · open source

lab-gate: check an AI-written experiment plan before it runs

In one sentence

lab-gate reads an experiment plan written by an AI agent, checks it against your lab's written rules, and gives one of three answers in milliseconds: safe to run (with proof), blocked (with the exact step that breaks a rule), or a human should decide.

pip install lab-gate

Free and open source (MIT). Python 3.12 or newer.

Who it's for

  • Engineers building self-driving labs or lab agents. Put lab-gate between the agent that writes plans and the instruments that run them. Every plan is checked before anything moves.
  • Lab managers and safety officers. Your limits (temperatures, instrument time, materials that must never be combined, steps that must happen in order) become rules that are checked the same way every time, with a record of what was checked.
  • Lab-as-a-service and shared facilities. Several partners send plans to the same instruments. Each plan is checked against the facility's rules before it is queued.

The problem it solves

AI agents now write experiment plans faster than people can review them. Two things go wrong:

  1. A plan can break a rule without any single step looking wrong. Five furnace runs can each be within limits while together they overrun the furnace. An agent can also split a forbidden goal into innocent-looking steps.
  2. Asking another AI model to check the plan is not reliable. In our tests, a frontier AI model asked to act as the safety check, given the full rules, let through 28% of attack plans (10 of 36). Even when given exactly the same information lab-gate uses, it still let through 8% (3 of 36). Its answers also changed between runs on the same plan.

lab-gate does not guess. It works through every step of the plan and every rule, and it gives the same answer every time.

What you get

AnswerWhat it meansWhat comes with it
PASSNo rule can be broken by this plan.A proof: two independent checkers (one of them a formal solver) agree no rule can be violated.
BLOCKA rule is broken.The rule, and the plan step by step up to the step that breaks it, so you can see and replay why.
ABSTAINlab-gate cannot decide safely (an unknown action, a missing or malformed value, a plan longer than it can check).The reason. The plan goes to a person. lab-gate never guesses.

Every answer also records a fingerprint (hash) of the rules and of the plan, so you can show later exactly what was checked against what.

Try it in five minutes

1. Install

pip install lab-gate

2. Get the example rules and plans

lab-gate examples my-first-check
cd my-first-check

This writes a rule file (rules.yaml) and three example plans.

3. Check a plan

lab-gate check plan_block.json --rules rules.yaml

You'll see:

verdict:   BLOCK
reason:    I3b violated: Total furnace occupancy must not exceed 240 minutes per campaign.

followed by the plan step by step, with the step that breaks the rule marked. Each anneal in this plan is fine on its own; together they overrun the furnace.

Try the other two:

lab-gate check plan_pass.json --rules rules.yaml      # PASS, with a proof
lab-gate check plan_abstain.json --rules rules.yaml   # ABSTAIN: unknown substrate, a human decides

4. Use it from your own code

from lab_gate import load_rules, check

rules = load_rules("rules.yaml")
result = check("plan_block.json", rules)

print(result.verdict)   # BLOCK
print(result.reason)    # I3b violated: Total furnace occupancy ...

In an agent loop: only send a plan to the instruments when result.verdict == "PASS". From the command line, the exit code tells you the same thing (0 PASS, 1 BLOCK, 2 ABSTAIN). Anything other than 0 means: do not run the plan as written.

Writing your own rules

Rules live in a plain YAML file. Each rule has a name, a sentence in plain English saying what it protects, and a precise limit. For example:

  - id: R1
    kind: accumulate
    plain_english: Total instrument time must not exceed 120 minutes per campaign.
    scope: any
    rationale: Protects shared instrument time.
    source: Facility booking policy.
    spec: {quantity: instrument_minutes, agg: sum, limit: 120}

There are four kinds of rule:

  • a limit on one step, e.g. a maximum temperature;
  • something that must never happen, or must happen in order, e.g. calibrate before measuring;
  • things that must never be combined;
  • a running total that must stay under a limit, e.g. furnace time per campaign.

If a rule names something lab-gate doesn't know, it refuses to load the rules rather than silently ignoring that rule. Full format: RULES.md. Complete commented example: rules.yaml.

What it can't do (read before relying on it)

  • It only knows the rules you give it. Harm that no rule describes gets through. In our tests, 20.6% of attack plans (7 of 34) reached a kind of harm that lab-gate had no rule for. Writing good rules is still a human job.
  • Tested in simulation only. All results come from a simulated electrochemistry lab built on the open HELAO framework. lab-gate has not yet been tested in a real lab.
  • The example rules are examples, not a safety policy. They show the shapes real rules take, using harmless quantities. Your lab writes its own.
  • Your rules can be wrong. lab-gate enforces them exactly, mistakes included.
  • Plans are checked up to 64 steps by default. Longer plans get ABSTAIN.
  • It does not judge whether the science is good. It only checks the rules.
  • Some checks need a dataset. Plans that measure specific material compositions use a public HELAO dataset for one rule. Run lab-gate fetch-data once to download it. Without it, those plans get ABSTAIN, never PASS.
  • It checks one plan at a time. One rule about instruments shared between several plans needs all of those plans at once; for a single plan, that rule is reported as not checked.

How well it works (simulation results)

lab-gateAI model as the safety check
Attack plans let through0 of 27728% (10 of 36)
Safe plans wrongly blocked0 of 13,627under 1% (1 of 294)
Same answer every runYesNo: 3% of plans changed answer between runs
Time per checkabout 3 ms typical, 20 ms for the slowest 5%not measured

Attack plans included fixed attacks, attacks split into innocent-looking steps, and an automated attacker that kept adapting until it ran out of tries. The evaluation plan was registered publicly before the final tests (OSF); the full report is on Zenodo.

Links

← All capabilitiesRead the essay: A safety check for robot labs →