Pydantic AI 2.40

Last reviewed Oct 28, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. Python 3155 lines · 3.8K tokens
  2. Pydantic 2.1356 lines · 1.3K tokens
  3. Pydantic AI 2.4098 lines · 3.9K tokens
Total309 lines · 9K tokens

CWE Coverage

  • 20
  • 23
  • 36
  • 59
  • 78
  • 89
  • 95
  • 117
  • 201
  • 208
  • 209
  • 214
  • 250
  • 295
  • 306
  • 319
  • 328
  • 338
  • 346
  • 347
  • 367
  • 379
  • 407
  • 409
  • 416
  • 426
  • 427
  • 470
  • 488
  • 502
  • 522
  • 532
  • 611
  • 639
  • 674
  • 732
  • 770
  • 772
  • 776
  • 807
  • 829
  • 862
  • 915
  • 916
  • 918
  • 1104
  • 1284
  • 1287
  • 1333
  • 1395
  • 1426
  • 1427

Prompt Preview

Apply the Pydantic 2.13 prompt first. These rules cover Pydantic AI 2.40 agents, capabilities, tools, MCP, message history, structured output, cost controls, realtime sessions, and observability.

Agent, model, and provider boundaries

  • Select the Model, provider, model identifier, profile, API base URL, credential, and HTTP client from trusted configuration; never pass a request-controlled provider:model string to model inference.
  • Construct provider credentials explicitly for production and keep them out of prompts, dependencies visible to tools, model settings, history, events, errors, and telemetry.
  • Leave defer_model_check=False to check provider configuration when a named model is resolved during construction; explicitly check per-run or capability-resolved models at startup before accepting traffic.
  • Allowlist run-time model and model_settings overrides. An Agent.override() or per-run setting must not let an untrusted caller change providers, weaken timeouts, expand token limits, or enable a preview capability.
  • Treat FallbackModel candidates as separate data recipients. Approve every candidate for the workload's data class, configure each candidate independently, and do not fall back after authentication, authorization, content-filter, or other policy failures.
  • Do not trust a model profile as authorization or a hard service guarantee. Test required tool, output, context-window, and realtime features against the exact provider deployment, and treat an unknown context window as unknown rather than unlimited.
  • Load Agent.from_file()