Expand description
Wire-level interop: guard LLM tool calls from any agent framework.
Agent frameworks (Pydantic AI, LangChain, the OpenAI and Anthropic SDKs) all share the same last-mile shape: the model emits a tool call — a tool name plus JSON arguments — and the host process decides whether to run it. That decision point is exactly where Typesec belongs, and it is the one place none of the frameworks guard for you.
This module provides:
ToolCallRequest— a framework-neutral, normalized tool call.ToolBinding— the declaration of how one tool maps onto the Typesec(action, resource)plane, optionally taking the resource from a tool argument.ToolCallGuard— evaluates normalized calls against anyPolicyEngine, deny-by-default for tools without a binding.- Dialect codecs (
openai,anthropic,langchain,pydantic_ai) that parse each framework’s wire shape intoToolCallRequests and render denials back in the shape the framework expects (an error tool-result / retry part), so a blocked call flows back to the model as feedback instead of crashing the run.
model output ─▶ dialect::parse_tool_calls ─▶ ToolCallGuard::check_all
│ Allow ─▶ run the tool
└ Deny ─▶ dialect::denial ─▶ modelThe typed ProtectedTool path remains the
strongest boundary (a capability is required to compile the call); this
module is the runtime bridge for tools that live on the other side of a
JSON wire, where Rust types cannot reach.
Modules§
- anthropic
- Anthropic Messages dialect:
tool_usecontent blocks in,tool_resultblocks withis_error: trueout. - dialects
- Named dialect registry: one dispatch table shared by every binding layer (Python, WASM, the CLI) so dialect names can’t drift between them.
- langchain
- LangChain dialect:
AIMessage.tool_callsin, errorToolMessages out. The same shapes serve LangGraph nodes, which pass LangChain messages. - mcp
- Model Context Protocol dialect: JSON-RPC
tools/callrequests in,isErrortool results out. - openai
- OpenAI Chat Completions dialect:
tool_callsin,role: "tool"denial messages out. Works with the OpenAI SDKs and any OpenAI-compatible server. - pydantic_
ai - Pydantic AI dialect:
tool-callmessage parts in,retry-promptparts out. Complements the capability metadata intypesec-integrations::pydantic_ai— the metadata declares the binding, this codec enforces it on the wire.
Structs§
- Guarded
Tool Call - A tool call together with its resolved binding and verdict.
- Tool
Binding - Declares how one tool maps onto the Typesec
(action, resource)plane. - Tool
Call Guard - Evaluates normalized tool calls against a policy engine.
- Tool
Call Request - One tool invocation requested by a model, normalized across frameworks.
Enums§
- Interop
Error - A framework payload could not be interpreted as tool calls.
- Taint
Error - Why tool output could not be protected.
- Tool
Call Verdict - The guard’s verdict on one tool call.
Constants§
- TOOL_
OUTPUT_ KIND - Resource kind attached to tool-output resources.