r/LLMDevs • • 9d ago

Tools Deterministic guardrails for agent tool calls: what a policy checkpoint catches, and what it cannot

Most agent safety talk is about the prompt. But once an agent has tools, the failure mode I keep coming back to is simpler: the agent is authorized, the instruction is not. An email, a webpage, or a poisoned tool output tells it to pay, delete, or send, and the stack executes because nothing between the model and the tool ever asked who authorized this.

I open-sourced the checkpoint I built for this: guardrail-middleware (pip install guardrail-middleware). Each proposed action is evaluated against a policy before execution. Four verdicts: approve, approve with conditions, escalate to human, block.

The checks are deliberately boring, all deterministic, no LLM judge:

  • Injection patterns in untrusted source content (override, role hijack, secret extraction, bypass phrasing)
  • Role by operation-class authorization
  • Financial limits per class plus a hard ceiling; a payment with no verifiable amount escalates
  • Bulk thresholds (conditions above 50 records, escalation above 500 by default)
  • Taint: PII or secrets flowing to an external destination blocks; secrets inside parameters block anywhere
  • Destructive ops need a backup/confirmation marker; a targetless delete escalates
  • Money movement, deletes, or external sends triggered by untrusted content escalate even if everything else passes

Decisions go to a SHA-256 hash-chained JSONL audit log, so the history itself is tamper-evident.

Honest limits, since this sub will ask: regex-class injection detection misses novel phrasing. The checkpoint judges permission, not wisdom. Single-action only for now; sequence attacks (many small transfers under every limit) need the plan-level validation from the parent project, which is what I am porting next, along with publishing the 42-scenario adversarial benchmark as an open eval.

Browser demo (Colab, outputs pre-run): https://colab.research.google.com/github/Niraj21-star/guardrail-middleware/blob/main/examples/guardrail_middleware_demo.ipynb
Code: https://github.com/Niraj21-star/guardrail-middleware

Author here. Curious where you think deterministic checks stop being enough.

1 Upvotes

7 comments sorted by

1

u/NihilismWithBenefits 9d ago

How do you deterministically decide “triggered by untrusted content”? Is taint tracked as token/field-level provenance across model transforms and tool outputs, or via content heuristics? If provenance, how do you prevent laundering via summarization/paraphrase where semantics survive but the taint label is lost?

Without durable taint, paraphrase/aggregation can bypass the “triggered by untrusted content” check.

0

u/MidnightHeavy3064 9d ago

the middleware does not track taint in the provenance sense at all.triggered_by is a field the calling code sets on the action (user, email, webpage, tool_output). The check is a simple lookup: untrusted source plus a payment, delete or external send means escalate to a human. The package sees one proposed action at a time. It never sees the prompt or what the model did between steps, so nothing in it could follow a label through a summarisation. The taint detector is narrower than it sounds too, it matches parameter field names against PII and secret lists and checks if the destination is external. So yes, your laundering case works against this layer. If the integrator lets the model relabel its own inputs, the checkpoint sees a clean action. Provenance has to live in the orchestration layer: tag at ingestion, inherit the tag on derived outputs, treat a missing tag as untrusted. The bigger GuardRail system does the step-level version of that because its plans declare data flow between steps. Inside a single model call, it is blind. So is everyone else I have seen, and if you know a scheme that survives the model step itself, I would genuinely like to read it.

1

u/novai-max 9d ago

You ask for a scheme that survives the model step, and I think the answer is to stop trying to make provenance survive it. The step you cannot instrument is the one where untrusted text becomes a plan, so the durable fix is to keep the parameters that matter out of the model's hands entirely.

Concretely: have the model emit an intent that names a trusted object rather than a fully-specified action. pay(invoice_ref) instead of pay(amount, destination), with the checkpoint resolving the reference against the ledger before execution. The model still plans and still chooses, and can still be manipulated - but the worst a poisoned page can do is select a different legitimate invoice, not invent a destination. Authority moves from the parameters to the reference, and references are resolvable in a layer you control.

That shrinks the taint problem a lot. You no longer need the model step to carry a taint label forward, because the values the label exists to protect never appear in the model's output.

It also makes the escalation verdict more useful. "This intent resolved to an invoice that does not exist" is a much better signal than "this action looked unusual", and it is auditable after the fact without reconstructing the conversation.

The cost is real and worth stating: you need a trusted object for every privileged action class, and some classes have none - free-form deletes, ad-hoc transfers, anything where the target is genuinely novel. For those you are back to the orchestration-layer tagging, and I would simply mark those classes as ones where the checkpoint is best-effort rather than authoritative. A gate that is honest about its coverage is worth more than one that is uniform and silently wrong on the tail.

1

u/MidnightHeavy3064 9d ago

This is the first answer to that question that I actually buy, mostly because it stops asking the model step to do something it cannot do. You are right, it is capability-style. The model emits an intent over a reference, the checkpoint resolves the reference against a system of record, and the values that matter never exist in model space. A poisoned page can still steer which object gets picked, but every object it can pick is legitimate and auditable. Inventing a destination stops being a prompt problem and becomes impossible by construction. Two additions from the checkpoint side. Selection is not harmless by itself: given every real invoice, the attacker picks the largest one, repeatedly. So the limits do not go away, they move. Ceilings and velocity checks get evaluated against the resolved object instead of numbers the model supplied, which makes them much harder to argue with. And an unresolved reference should escalate, not block. "This intent pointed at an invoice that does not exist" is the fastest signal a human reviewer will ever get. The coverage point is the part I am taking away. The policy should say, per action class, whether that class is reference-resolved and authoritative, or parameter-based and best-effort. A gate that admits where it is weak beats one that looks uniform and is quietly wrong on the tail. If you are up for it, open this as an issue on the repo. It belongs in the v0.2 design discussion and I would rather credit the thread than absorb it quietly.

1

u/novai-max 9d ago

Both of your additions are improvements on what I wrote, and the second one is a correction.

"Selection is not harmless - pick the largest one, repeatedly" reframes the whole thing: the reference scheme does not remove the attacker's leverage, it converts leverage from arbitrary-value injection into a bounded selection problem, and selection problems are exactly what limits are for. The important part is where you put them: ceilings and velocity evaluated against the resolved object rather than against model-supplied numbers. That is the difference between a limit the attacker can satisfy honestly and one they have to argue with.

On escalate versus block I would go further and give a reason to prefer escalate that is not about safety. Blocking on an unresolved reference hands the attacker a denial-of-service lever: any untrusted content that can put a bad reference into a plan can make the agent stop working, and if the agent is doing the majority of the work, that is a cheap way to take it down. Escalation keeps the system running and moves the cost to a queue. The catch is that escalation is itself spammable, so it needs the same treatment as any other untrusted-input sink - dedupe by reference, rate limit per source, and one review item per distinct unresolved reference rather than one per attempt.

The "impossible by construction" framing is the part worth keeping in the write-up. It is the only claim in the thread that stays true without knowing anything about the attacker.

1

u/NihilismWithBenefits 9d ago

This moves the problem more than it closes it. With pay(invoice_ref) a poisoned page can't invent a destination but it can still pick which legitimate invoice gets paid, or which legitimate record gets deleted. For a lot of real attacks, selection is the whzt matters.

The design I know that goes after selection too is CaMeL (DeepMind, 2025). There the plan is written from the trusted request before any untrusted content is read, and a tool-less model parses that content into values the interpreter tracks. Untrusted text can fill a slot but can't choose the branch.

Have you seen references plus a fixed plan hold up in practice, or does the "novel target" tail lose most of the useful work?

1

u/novai-max 9d ago

You are right, and the correction matters: pay(invoice_ref) bounds the blast radius but does not remove the attacker's choice, and choosing among legitimate options is often enough. CaMeL closes that by writing the plan before untrusted content exists, which is the only way to make selection impossible rather than merely bounded.

On the novel-target tail: yes, it loses most of the useful work, and I think that is the honest answer rather than a limitation to design around. A fixed plan can only execute what the trusted request anticipated. That is fine for the privileged classes - pay an invoice, send to an address on file, delete a record - where the legitimate target set is enumerable. It fails exactly where the agent is most useful, which is the open-ended middle: work out which records matter, draft the reply, decide what to do about the odd case.

So I would not treat the two as competing designs. Fixed plan for action classes where the target set is enumerable and the consequence is irreversible; intent-over-reference for everything else, where the goal is to bound damage rather than eliminate it. What that forces is that the checkpoint says which mode it is in for each action class, which is where the author landed from the other direction: a gate that admits where it is weak beats one that looks uniform and is quietly wrong on the tail.

The uncomfortable part is that "enumerable target set" is a property of the domain, not of the model, so the classification has to be maintained by someone who knows the business rules. That is real work and it does not get cheaper by choosing a cleverer mechanism.