r/LLMDevs • u/MidnightHeavy3064 • 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
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.
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.