In this article
Bind sensitive tool authority to authenticated server-side caller state, and treat client-submitted history as conversation input rather than an approval ledger.
Identify who controls the submitted conversation
A web client sends prior messages and approval decisions when continuing an agent run. Pydantic AI’s history guide describes its server-side surfaces as stateless: they reconstruct a run from submitted history and deferred results. A client that can supply those objects can fabricate tool calls or approval entries. Their presence in the accepted history is therefore not independent evidence that a model originally proposed them or a person reviewed them.
Use sanitization for its actual scope
The guide provides sanitize_messages to constrain untrusted history. It strips or resets fields such as client-supplied system instructions, workspace references and reserved framework metadata under the documented defaults. These measures narrow what submitted messages can influence. They do not cryptographically establish the origin of every call, result or approval. Keep that distinction visible when deciding whether client-held conversation state can authorize an external write.
Authenticate the route and constrain its tools
The deferred-tool guide explicitly distinguishes human sign-off from application authorization. Authenticate the endpoint and expose tools appropriate to the caller. A user allowed to continue a conversation is not automatically entitled to every target accepted by a broadly configured file-update tool. Validate the resource relationship inside the operation that will create the effect, using state the application actually controls.
Carry caller context through dependencies
The dependencies guide passes application objects into each run and exposes them through RunContext.deps. Use trusted caller identity and authorization services from the route’s own context, rather than deriving them from a sentence or metadata object inside client history. The dependency type supports application structure; it does not make untrusted values safe merely because they fit that type. Establish their provenance before constructing the run.
Keep the review record where its authority lives
For sensitive paused work, the history guide recommends checking against server-side state or persisting the paused run and supplying the application’s own deferred results. Task contracts define the allowed target and outcome; tool observations record the actual operation. Conversation content can still support useful continuation. Its role is context, while the permission to change an external resource comes from the application’s authenticated authority and retained review state.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.