Questions and fixes
Why did my call not run?
Look at the guard’s decision. It lists the broken rules and the option it picked:
from causalrepair import Guard, Policy, ToolCall, require_confirmation
policy = Policy(guarded={"refund"}).add(require_confirmation())
session = Guard(policy).session()
session.user("Refund order A1.")
reply = session.run(ToolCall("refund", {"order_id": "A1", "amount": 5}), lambda order_id, amount: "done")
print(reply.status, reply.decision.intervention, [v.message for v in reply.decision.violations])
It prints:
blocked confirm_first ['refund changes state but the user has not explicitly confirmed (yes) this action.']
session.records has the same facts for every checked call.
I get the warning “the guard has seen no user message”
require_confirmation needs to see what the user says. Call session.user(text) for every user message, or adapters.sync(session, messages) if you keep a chat message list. Without user messages, no call can ever be confirmed.
The user said “yes”, but the guard still asks for it
- Only the latest user message counts. If the user said “yes” and then sent another message, the “yes” no longer counts.
- The guard must see the message: check that you called
session.user(...)orsync(...)before the call. - Only some words count (yes, sure, go ahead, ok, …). See Built-in rules to use your own words.
TypeError: “… is async: use await session.arun(…)”
The tool is an async def function. Use await session.arun(call, fn) or await session.acall(call, execute), or wrap it with session.tools(...), which keeps it async. See Async tools.
ValueError: mode “learned” needs a fitted Artifact
Fit one first (Learn from logs) and pass it: Guard(policy, mode="learned", artifact=Artifact.load(path)).
ValueError: chooser picked …, which is not on the menu
Your chooser returned an option that is not allowed for this call. Return only names from the menu it receives.
A rule says “could not be checked”
The rule raised an error, for example a missing key in call.args or in trace.context. The guard then counts the rule as broken, so that no call slips through. Fix the rule, or make sure the session has the context it reads: guard.session(customer_id=...).
Can a learned guard run a call that breaks a rule?
No. Every mode picks from the menu, and the menu holds only options that break no rule. The learned guard only chooses which allowed option to use. Only mode="off" runs calls that break rules (it is meant for measuring a baseline).
Can text in a tool result or a web page trick the guard?
The guard trusts only the user’s messages, the tool results it recorded and its own records. sync reads only the text of user and assistant turns, so a tool result is never taken for something the user said. To stop actions the user never asked for, use the must_match_request rule (Built-in rules).
Does the guard call a language model, or send my data anywhere?
No. The library is plain Python with numpy and scipy. It makes no network calls. (The benchmark code does call the model servers that you give it.)
Does it work with my agent framework?
If the framework takes Python functions as tools, give it the wrapped tools from session.tools(...). They keep the name, docstring and signature. If the framework runs the tools itself, use session.call(call, execute) or session.review(...) with session.observe(...). See Connect your agent.
How do I run the tests?
pip install -e ".[test]"
pytest
Some benchmark tests are skipped when the benchmark is not installed, or when they need the paper’s recorded runs.