raxit
Frameworks

DSPy

Governing DSPy agents in Python, zero-code.

DSPy has two independent, live tool-dispatch surfaces, and raxit's auto-patcher governs both: dspy.adapters.types.tool.Tool.__call__/.acall — what a dspy.ReAct loop's forward/aforward calls internally — and dspy.ToolCalls.ToolCall.execute, DSPy's separate "native tool calling" pattern that resolves and calls the target function directly, bypassing Tool.__call__ entirely. Either way, every tool call resolves to permit / defer / deny before it executes, with no governance code in the agent. Python only — dspy has no JS/TS SDK.

Run it yourself

For your own DSPy agent, install the SDK and launch it under raxit run:

pip install raxit
raxit run -- python your_agent.py

Run the same file without raxit run and it runs ungoverned — governance is a deploy-time choice, not a code change.

How it works

Tools are ordinary dspy.Tool instances with no governance code. The only "wiring" is each tool's name, the policy resource it's governed as:

# your_agent.py — imports NOTHING from raxit
from dspy.adapters.types.tool import Tool

def db_write(payload: str) -> str: ...

tools = [Tool(db_write, name="db.write")]
react = dspy.ReAct("question -> answer", tools=tools)
.raxit/security.yaml
apiVersion: raxit.security/v1
agent: dspy-bot
default: block
rules:
  - effect: allow
    resource: fetch_docs
  - effect: review              # unconditional review == defer.policy
    resource: db.write
  # shell.exec is intentionally UNLISTED -> default-deny (deny.default_or_forbid).

A denied or deferred call raises raxit.autopatch.RaxitDenied from inside Tool.__call__, carrying the reason code — the tool body never executes. raxit explain <call_id> shows the full decision record.

Real captured output from a run:

[PASS] autopatch: install() governed the dspy Tool.__call__ dispatch — patched={'dspy': ['__call__', 'acall', 'execute']}
  fetch_docs   -> permit  -> ran
  db.write     -> defer  -> RaxitDenied raised: reason=defer.policy
  shell.exec   -> deny   -> RaxitDenied raised: reason=deny.default_or_forbid
  audit.verify  -> ok=True signatures_verified=True signed_count=3 count=3
all checks PASS

Scope: this page drives Surface 1 only

This example drives only Tool.__call__ (Surface 1 — what dspy.ReAct itself uses). The second surface, ToolCalls.ToolCall.execute (Surface 2, native tool calling without ReAct), is also governed by raxit's auto-patcher and is confirmed live — including MODIFY on both surfaces — in our test suite, exercised there rather than in this worked example.

What got denied and why

  • defer.policydb.write matched the review rule; it's suspended for human approval (see Approvals). The demo runs with RAXIT_DEFER_TIMEOUT=0, so the defer surfaces as a raised RaxitDenied rather than blocking inline.
  • deny.default_or_forbidshell.exec appears nowhere in the policy, so it falls to default: block. The tool body never ran, confirmed by the demo's own call log.

Every decision — the permit, the defer, and the deny — lands in one hash-chained, Ed25519-signed Decision Provenance log, verified green with client.audit.verify(signatures=True). See Audit and Decisions for the full permit / defer / deny vocabulary and reason-code catalog.

On this page