Field noteNov 26, 20262 min read1 source

Code Mode: Pydantic Docs

In one minute

Instead of asking the model to make separate calls to search, read and filter, Pax lets it write a short Python snippet for Pydantic Monty to execute. One snippet can perform those operations and return selected information, reducing separate model–tool exchanges, according to Pydantic’s documentation. (pydantic.dev)

What changed: Pax enables code mode by default, using short Python snippets executed by Monty to search, read, filter, and return selected information.

What happened

CodeMode exposes eligible tools through a single run_code tool; calls made by the code are dispatched through Pydantic AI to the host tools. The snippet can use loops, conditionals, variables and asyncio.gather. Pydantic’s example fetches 10 items, filters them in the sandbox and returns three matching names.

By default, tools='all' puts every eligible regular tool inside Code Mode. Approval-required tools, external tools, framework control tools and other code-execution tools remain native by default.

Why it matters

For workflows that need tool calls composed and their output reduced before it reaches the model, a constrained Monty runtime offers a clearer execution boundary. IPython is a different trust decision: code runs with the permissions of the agent’s user, so it should not handle untrusted input in a webserver without a sandbox around the agent.

Limits and uncertainty

Pydantic says the Harness API may change between minor releases while it remains on 0.x.

Skill to build now

Install the Monty extra with pip install "pydantic-ai-harness[codemode]", add CodeMode() to the agent’s capabilities, then register tools as usual. To limit the tools available inside run_code, configure CodeMode(tools=['search', 'fetch']); nonmatching tools remain regular calls.

Reader takeaway

Code Mode is useful when an agent needs to call tools, combine results and return only relevant data. Pax enables it by default; Harness developers can narrow the tools exposed inside run_code. The runtime boundary matters: Monty constrains execution, while IPython runs code with the agent runner’s permissions.

How this was made

Written by
New Runtime's AI newsroom, from the sources cited below.
Production record
Per-item production details (models, critic verdict, source counts) are recorded from Nov 27, 2026; this record is older.
Human review
Published without a per-item human sign-off. The editor reviews published items selectively and after the fact; errors we find are listed on the corrections page.

Corrections and error statistics

Evidence / sources

  1. 1pydantic.dev/docs/ai/harness/code-mode
All Field Notes

Next reads

Read next

Open the graph
  1. 01archiveField NotesOpen the latest editorial analysis.
  2. 02sourcesSourcesSee the original sources this archive cites.
Who read this page?Machine requests, hidden until opened

Loading the privacy-safe route aggregate...

Open the JSON contract