Pydantic AI integration for LatchGate — execution security kernel for AI agents
Project description
latchgate-pydantic-ai
Pydantic AI integration for LatchGate — execution security kernel for AI agents.
Every tool call goes through LatchGate's enforcement pipeline: auth => policy => WASM sandbox => verification => signed receipt. The LLM never holds credentials and never contacts external systems directly.
Installation
pip install latchgate-pydantic-ai
Requires a running LatchGate instance:
curl -fsSL https://raw.githubusercontent.com/latchgate-ai/latchgate/main/install.sh | bash && latchgate up
Quick start
from pydantic_ai import Agent
from latchgate_pydantic_ai import LatchGateToolset
async def main():
async with await LatchGateToolset.create(gate_url="http://localhost:3000") as toolset:
agent = Agent(
"openai:gpt-4o",
instructions="You have access to LatchGate-protected tools with full audit trail.",
toolsets=[toolset],
)
result = await agent.run("Fetch https://httpbin.org/get")
print(result.output)
API
LatchGateToolset
Native Pydantic AI AbstractToolset implementation. Discovers actions and provides them to the agent via toolsets=[...].
toolset = await LatchGateToolset.create(
gate_url="http://localhost:3000", # Required (or set LATCHGATE_URL)
agent_id="my-agent", # Default: "pydantic-ai"
include={"http_fetch", "database"}, # Optional
exclude={"send_message"}, # Optional
on_audit=my_audit_callback, # Optional: receipt callback
)
agent = Agent("openai:gpt-4o", toolsets=[toolset])
# Properties:
toolset.action_ids # list[str]
toolset.client # LatchGateClient
Use as an async context manager for automatic cleanup:
async with await LatchGateToolset.create(gate_url="...") as toolset:
agent = Agent("openai:gpt-4o", toolsets=[toolset])
Or construct from pre-fetched descriptors:
toolset = LatchGateToolset(client=client, descriptors=descriptors)
discover_actions(gate_url, **kwargs)
Low-level discovery:
from latchgate_pydantic_ai import discover_actions
descriptors = await discover_actions("http://localhost:3000", include={"http_fetch"})
Error handling
LatchGate errors are returned as structured strings (not raised):
| LatchGate error | Tool returns |
|---|---|
| Policy denied | "ERROR: Action '...' denied: {reason}..." |
| Approval required | "ERROR: ... requires human approval..." (approval_id emitted via log, not to the model) |
| Budget exhausted | "ERROR: Budget exhausted..." |
| Unknown action | "ERROR: Unknown LatchGate action '...'." |
| Transport / infra | "ERROR: LatchGate error..." |
Output format
Tool output is a JSON string containing only the action result. Enforcement metadata (receipt ID, trace ID, verification) is never returned to the model — it is emitted at INFO log level and via the optional on_audit callback.
{"status": 200, "body": "{...}"}
Why AbstractToolset?
Pydantic AI's AbstractToolset is the native interface for external tool collections. It provides get_tools() for schema discovery and call_tool() for execution — matching LatchGate's discovery + execute pattern perfectly. No schema-to-Pydantic model conversion needed; JSON Schemas pass through directly via ToolDefinition.parameters_json_schema.
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file latchgate_pydantic_ai-0.1.1.tar.gz.
File metadata
- Download URL: latchgate_pydantic_ai-0.1.1.tar.gz
- Upload date:
- Size: 229.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc995551b0aba83a5cbbd04daf59f46942d6041c9a95b05cb33c30a6c79edea7
|
|
| MD5 |
8899cd111f3a21676ff7aed381140f37
|
|
| BLAKE2b-256 |
713bfcaa28666c32d66c55838d70a3c91c2be617d81d9ed96c22ff1c0645d215
|
Provenance
The following attestation bundles were made for latchgate_pydantic_ai-0.1.1.tar.gz:
Publisher:
release.yml on latchgate-ai/latchgate-integrations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
latchgate_pydantic_ai-0.1.1.tar.gz -
Subject digest:
dc995551b0aba83a5cbbd04daf59f46942d6041c9a95b05cb33c30a6c79edea7 - Sigstore transparency entry: 1754733973
- Sigstore integration time:
-
Permalink:
latchgate-ai/latchgate-integrations@00b7380c470ac7386569e68d1cf429a1e2354829 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/latchgate-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@00b7380c470ac7386569e68d1cf429a1e2354829 -
Trigger Event:
push
-
Statement type:
File details
Details for the file latchgate_pydantic_ai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: latchgate_pydantic_ai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8cb9daae827b3f44a127084ffc14013c2817e4ed9b2875cc7b9a32e555f230e
|
|
| MD5 |
f5d31c4116a75c6c4f84b45d6318e93c
|
|
| BLAKE2b-256 |
fbdbf196a6e1be80ecca0a5bce4698f87dc7938ef4e290ed60ab94fdc469044f
|
Provenance
The following attestation bundles were made for latchgate_pydantic_ai-0.1.1-py3-none-any.whl:
Publisher:
release.yml on latchgate-ai/latchgate-integrations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
latchgate_pydantic_ai-0.1.1-py3-none-any.whl -
Subject digest:
b8cb9daae827b3f44a127084ffc14013c2817e4ed9b2875cc7b9a32e555f230e - Sigstore transparency entry: 1754733974
- Sigstore integration time:
-
Permalink:
latchgate-ai/latchgate-integrations@00b7380c470ac7386569e68d1cf429a1e2354829 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/latchgate-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@00b7380c470ac7386569e68d1cf429a1e2354829 -
Trigger Event:
push
-
Statement type: