Skip to main content

Module interop

Module interop 

Source
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 any PolicyEngine, deny-by-default for tools without a binding.
  • Dialect codecs (openai, anthropic, langchain, pydantic_ai) that parse each framework’s wire shape into ToolCallRequests 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 ─▶ model

The 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_use content blocks in, tool_result blocks with is_error: true out.
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_calls in, error ToolMessages out. The same shapes serve LangGraph nodes, which pass LangChain messages.
mcp
Model Context Protocol dialect: JSON-RPC tools/call requests in, isError tool results out.
openai
OpenAI Chat Completions dialect: tool_calls in, role: "tool" denial messages out. Works with the OpenAI SDKs and any OpenAI-compatible server.
pydantic_ai
Pydantic AI dialect: tool-call message parts in, retry-prompt parts out. Complements the capability metadata in typesec-integrations::pydantic_ai — the metadata declares the binding, this codec enforces it on the wire.

Structs§

GuardedToolCall
A tool call together with its resolved binding and verdict.
ToolBinding
Declares how one tool maps onto the Typesec (action, resource) plane.
ToolCallGuard
Evaluates normalized tool calls against a policy engine.
ToolCallRequest
One tool invocation requested by a model, normalized across frameworks.

Enums§

InteropError
A framework payload could not be interpreted as tool calls.
TaintError
Why tool output could not be protected.
ToolCallVerdict
The guard’s verdict on one tool call.

Constants§

TOOL_OUTPUT_KIND
Resource kind attached to tool-output resources.