Repository guide · source walkthrough · v7
pydantic / pydantic-ai · Source walkthrough
A reading order for this repository's analyzed revision. It starts with file-level blocks under .claude and .github/scripts, then the parse_cassette.py guard and main. It moves to library blocks and to selected classes in messages, exceptions, _utils and models, and ends with coupled blocks to check before changing code. Every block note is a static inference.
- Original repository
- pydantic/pydantic-ai
- License
- MIT · open-source license
- Analyzed revision · last verified
- a0022cd089c90121f101f7966fdb492a092d4330 ·
Newer revision observed; parts of this guide may be outdated. The default branch moved to f93bcff0c72c, checked 2026-11-15. The whole guide describes revision a0022cd089c9. A revision diff found changes in 11 code regions it cites (listed below); statements about those regions may not hold at the new revision and have not been rechecked yet.
- pydantic_ai_slim/pydantic_ai/agent/__init__.py:1650-2339 · lines changed
- pydantic_ai_slim/pydantic_ai/ui/vercel_ai/_adapter.py:388-843 · lines changed
- pydantic_ai_slim/pydantic_ai/ui/vercel_ai/_adapter.py:384-847 · lines changed
- src/pydantic_clai2/pydantic_clai2/runtime/session_runtime.py:158-575 · lines changed
- pydantic_ai_slim/pydantic_ai/models/bedrock.py:1758-2153 · lines changed
- pydantic_ai_slim/pydantic_ai/messages.py:2060-2391 · lines changed
- … and 5 more
pydantic/pydantic-ai source walkthrough: a static reading order
Terms used on this page
- Entrypoint record
- A file the analyzer marks as a place where execution can start. When it carries a __main__ guard excerpt, the file contains an if __name__ == "__main__": block and the excerpt shows what that block calls; without an excerpt, the file was flagged by its name only.
- Bounded static execution path
- A call chain reconstructed from the source code without running it, stopped after a fixed number of steps. It shows how far the code can be followed on paper, not what happens at run time.
- Unresolved boundary
- Where a static path stops because the next call goes into an external library or cannot be resolved without running the code. It marks the edge of this analysis, not a defect in the repository.
- Static relations
- Calls and imports found in the source. "External or unresolved" relations point outside the analyzed files.
- Module role
- The analyzer's label for a file, inferred from how many calls go in and out (for example core, entry/orchestration, leaf). It describes a position in the call graph, not the authors' design.
- Test-like files
- Files whose names or locations look like tests. This analysis counts them; it does not run them.
- Observed · inferred · author-claimed · unresolved
- How each statement is supported: read directly from the analyzed files; derived by the analyzer from them; stated by the repository's authors (metadata, README); or not established by this analysis.
- Verified
- Two uses on these pages. In an analyzer record ("verified provenance", "a verified entrypoint") it means the record was read directly from the analyzed files, which these guides call observed; for an entrypoint, the __main__ guard text is present. Since the analyzer fix of 2026-10-04, a file that only has an entrypoint-like name such as cli.py or main.py is recorded as inferred; guides analyzed before that still call such a file verified, and it is still only a guess about how the file is used. It does not mean the code was run or tested. "Last verified" is the date the guide last passed the lab's checks against the analysis record of the stated revision; it is not a review of the repository itself.
How to use this walkthrough
This walkthrough has four stops that follow the analyzer's own lessons: orientation, execution story, core code (with an added library reading set) and change guide. A final section covers what the analysis cannot show. Each bullet names one block as path:start-end. That range is the block's recorded line span in the analyzed revision's files, not a range computed here. A block is the analyzer's line-addressable unit of code. The description given for a block is the analyzer's inference with a confidence value, not a reading of the code. Open each range and read it yourself; this guide only says why it was listed.
Stop 1: Orientation
The orientation lesson starts with file-level blocks, and all six of them lie outside library code. One is a file under .claude/skills and five are under .github/scripts. The analyzer's note for each is generic: the block is the file-level container for that file, and its symbol is the file itself. The analyzer also marked parse_cassette.py as important because it is likely an entrypoint, and a direct-execution guard was parsed in that file.
.claude/skills/testing-skill/parse_cassette.py:1-104— module block; confidence 0.9..github/scripts/agent_provider_health.py:1-1414— module block; confidence 0.76..github/scripts/agent_spend_report.py:1-590— module block; confidence 0.76..github/scripts/agentic_workflow_guard.py:1-1618— module block; confidence 0.76..github/scripts/check_api_compatibility.py:1-406— module block; confidence 0.76..github/scripts/ci_duration.py:1-912— module block; confidence 0.76.
Stop 2: Execution story
The execution-story lesson has two blocks, both in parse_cassette.py. The listed bounded path records all start at that file's guard and enter main. Each one ends at an unresolved boundary on calls such as argparse.ArgumentParser, parser.add_argument, parser.parse_args and args.cassette.exists. One of the analyzer's teaching claims says no bounded static execution path is available. That conflicts with these records, so treat the runtime flow as not established.
.claude/skills/testing-skill/parse_cassette.py:103-104— main_guard, symbol__main__. The analyzer says it gates code that runs when the file is executed directly rather than imported (confidence 0.99)..claude/skills/testing-skill/parse_cassette.py:89-100— functionmain(def main() -> None:). Static structure suggests it encapsulates an operation with 8 downstream call or import relations (confidence 0.76).
Stop 3: Core code
Six of the core-code lesson's eight blocks lie in library code. The other two are the parse_cassette.py guard and main from the previous stop. For the five function blocks below, the analyzer says only that each encapsulates an operation connected to the given number of downstream call or import relations.
pydantic_ai_slim/pydantic_ai/exceptions.py:302-310— classUserError; groups related behavior under one class boundary (confidence 0.97).pydantic_ai_slim/pydantic_ai/ui/vercel_ai/_adapter.py:384-847— functionVercelAIAdapter.load_messages; 193 relations.src/pydantic_clai2/pydantic_clai2/runtime/session_runtime.py:158-575— functioncreate_shell; 152 relations.pydantic_ai_slim/pydantic_ai/common_tools/web_fetch.py:298-523— function_convert_html; 143 relations.pydantic_ai_slim/pydantic_ai/models/bedrock.py:1758-2153— functionBedrockConverseModel._map_messages; 133 relations.pydantic_ai_slim/pydantic_ai/agent/__init__.py:1650-2339— functionAgent._prepare_run; 124 relations.
The library reading set that follows is the AI Frontier lab's selection by static call degree, not an analyzer lesson. It covers four modules with two long blocks each. All eight are class blocks that the analyzer describes as grouping related behavior under one class boundary.
messages.py: service/core candidate, 497 incoming and 102 outgoing calls.pydantic_ai_slim/pydantic_ai/messages.py:2060-2391— classBaseToolReturnPart(0.99).pydantic_ai_slim/pydantic_ai/messages.py:4580-4862— classModelResponse(0.97).
exceptions.py: leaf/data-boundary candidate, 541 incoming and 0 outgoing calls.pydantic_ai_slim/pydantic_ai/exceptions.py:344-520— classRunCancelled(0.97).pydantic_ai_slim/pydantic_ai/exceptions.py:917-1092— classModelHTTPError(0.97).
_utils.py: service/core candidate, 313 incoming and 6 outgoing calls.pydantic_ai_slim/pydantic_ai/_utils.py:722-827— classPeekableAsyncStream(0.97).pydantic_ai_slim/pydantic_ai/_utils.py:336-439— classScopedTask(0.97).
models/__init__.py: service/core candidate, 165 incoming and 127 outgoing calls.pydantic_ai_slim/pydantic_ai/models/__init__.py:747-2140— classModel(0.99).pydantic_ai_slim/pydantic_ai/models/__init__.py:2144-2456— classStreamedResponse(0.99).
Stop 4: Where changes ripple
The change-guide lesson lists six blocks where the static graph shows stronger coupling. Three lie in library code. The other three lie in a test helper and a .github script, so part of the coupling signal here comes from test or tooling code. That test helper module, tests/clai2/menu_script.py, also has the highest incoming call count in the module role list, as a leaf/data-boundary candidate.
pydantic_ai_slim/pydantic_ai/exceptions.py:302-310— classUserError; groups related behavior under one class boundary (0.97).pydantic_ai_slim/pydantic_ai/ui/vercel_ai/_adapter.py:384-847— functionVercelAIAdapter.load_messages; 193 downstream relations.pydantic_ai_slim/pydantic_ai/ui/vercel_ai/_adapter.py:388-843— for block insideVercelAIAdapter.load_messages; repeats a region according to its loop condition or iterable.tests/clai2/menu_script.py:33-34— functionpick; 3 downstream relations.tests/clai2/menu_script.py:34-34— straight_line block of sequential statements insidepick..github/scripts/agentic_workflow_guard.py:1149-1471— functioncheck_provider_health_monitor; 225 downstream relations.
What this walkthrough cannot show
Everything above comes from static analysis. The block descriptions are inferences with confidence values, not runtime proof. The uncertainties lesson adds no blocks of its own. The analysis records these limits:
- Reflection, runtime dependency injection, dynamic imports, monkey-patching, generated code, framework runtime wiring and dynamic dispatch are not resolved.
- Install, run and build inference is partial and installation commands are not verified, so none are given here.
- Files over 400 kB, minified bundles and vendored directories are inventoried but not parsed; nine files were skipped this way.
- The repository relation cap was reached, so call counts and coupling signals may be incomplete.
- Eight entrypoint paths have no statically detected call steps.
What this analysis could not establish
The writing model's own notes on the analysis record. Identifiers such as lim_3, exec_* or claim_… name records of that analysis; the claims table cites the same records.
- The analyzer's repository summary calls this a web or Node.js application, while the primary language metadata is Python; this walkthrough does not rely on that summary.
- One teaching claim names examples/pydantic_ai_examples/slack_lead_qualifier/app.py as a starting point, while the orientation lesson and repository summary point to .claude/skills/testing-skill/parse_cassette.py.
- A teaching claim says no bounded static execution path is available, yet path records starting at parse_cassette.py are listed.
- pydantic_ai_slim/pydantic_ai/models/openai.py was skipped as larger than 400 kB, so its code is not represented in blocks or relations.
- The repository relation cap was reached, so files later in the extraction order have no relation edges and call degrees may be understated.
Claims and evidence — 27 claims, 27 supported by an independent verifier
Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.
| Claim | Epistemic status | Verifier | Grounding (global IDs) |
|---|---|---|---|
| c1 Every line range here is a block's recorded lines value. A block is the analyzer's line-addressable unit, and its description is the analyzer's inference with a confidence value. | inferred | supported | analysis_947322335585c32a:block_610b8db2be294c, analysis_947322335585c32a:block_e0cc5f8a441d6d, analysis_947322335585c32a:block_00b21f58abc199 |
| c2 The stops follow the analyzer's orientation, execution-story, core-code and change-guide lessons, plus a library reading set inside the core-code stop; this guide lists their blocks as places to read. | inferred | supported | analysis_947322335585c32a:block_610b8db2be294c, analysis_947322335585c32a:block_dbf176e51e7398, analysis_947322335585c32a:block_9fbd3e13343e7c, analysis_947322335585c32a:block_38e439e8e58911, analysis_947322335585c32a:role_215 |
| c3 The orientation lesson lists six file-level module blocks outside library code. The analyzer describes each only as the file-level container for its file, with confidence 0.9 for parse_cassette.py and 0.76 for the five .github/scripts files. | inferred | supported | analysis_947322335585c32a:block_610b8db2be294c, analysis_947322335585c32a:block_5b6ec584ae1d19, analysis_947322335585c32a:block_99b9814c99ad79, analysis_947322335585c32a:block_81ddc60d9a3848, analysis_947322335585c32a:block_230c8306f73c49, analysis_947322335585c32a:block_8ee30612680fe2 |
| c4 The analyzer classified .claude/skills/testing-skill/parse_cassette.py as important because it is likely an entrypoint, and a __main__ guard was parsed in that file. | inferred | supported | analysis_947322335585c32a:claim_e74c614d2f49, analysis_947322335585c32a:py_entry_e9ef1059e87f |
| c5 The block at .claude/skills/testing-skill/parse_cassette.py:103-104 is a main_guard that the analyzer says gates code run when the file is executed directly rather than imported, with confidence 0.99. | inferred | supported | analysis_947322335585c32a:block_dbf176e51e7398, analysis_947322335585c32a:py_entry_e9ef1059e87f |
| c6 The function block main at .claude/skills/testing-skill/parse_cassette.py:89-100 is described as encapsulating an operation with 8 downstream call or import relations, with confidence 0.76. | inferred | supported | analysis_947322335585c32a:block_e0cc5f8a441d6d, analysis_947322335585c32a:py_func_c7f0c5a08569 |
| c7 The listed bounded path records start at the parse_cassette.py guard, enter main, and end at an unresolved boundary on calls such as argparse.ArgumentParser, parser.add_argument, parser.parse_args and args.cassette.exists. | inferred | supported | analysis_947322335585c32a:exec_bb0400b95179, analysis_947322335585c32a:exec_9bbb24a4ce38, analysis_947322335585c32a:exec_1fdb044ec706, analysis_947322335585c32a:exec_06af0227393f, analysis_947322335585c32a:exec_5f90db10d033 |
| c8 A teaching claim states that no bounded static execution path is available. This conflicts with the listed path records, so the runtime flow is not established. | inferred | supported | analysis_947322335585c32a:claim_4d30ade3e21e, analysis_947322335585c32a:exec_bb0400b95179 |
| c9 Six of the core-code lesson's eight blocks are flagged as library code. The two others are the parse_cassette.py guard and main. | inferred | supported | analysis_947322335585c32a:block_dbf176e51e7398, analysis_947322335585c32a:block_e0cc5f8a441d6d, analysis_947322335585c32a:block_00b21f58abc199, analysis_947322335585c32a:block_60429d3e04e54a, analysis_947322335585c32a:block_a42bc69b7b3931, analysis_947322335585c32a:block_77f3b86b63419f, analysis_947322335585c32a:block_e6898e28b8643e, analysis_947322335585c32a:block_9fbd3e13343e7c |
| c10 UserError at pydantic_ai_slim/pydantic_ai/exceptions.py lines 302-310 is a class block described as grouping related behavior under one class boundary, with confidence 0.97. | inferred | supported | analysis_947322335585c32a:block_00b21f58abc199, analysis_947322335585c32a:py_class_1a7aa408702e |
| c11 VercelAIAdapter.load_messages, create_shell, _convert_html, BedrockConverseModel._map_messages and Agent._prepare_run are function blocks described as encapsulating an operation with 193, 152, 143, 133 and 124 downstream relations. | inferred | supported | analysis_947322335585c32a:block_60429d3e04e54a, analysis_947322335585c32a:block_a42bc69b7b3931, analysis_947322335585c32a:block_77f3b86b63419f, analysis_947322335585c32a:block_e6898e28b8643e, analysis_947322335585c32a:block_9fbd3e13343e7c |
| c12 The library reading set is the AI Frontier lab's selection by static call degree, not an analyzer lesson. Its eight blocks are class blocks described as grouping related behavior under one class boundary. | inferred | supported | analysis_947322335585c32a:role_215, analysis_947322335585c32a:role_195, analysis_947322335585c32a:role_110, analysis_947322335585c32a:role_216, analysis_947322335585c32a:block_34ca40817a0242, analysis_947322335585c32a:block_bd059aeb4397d5, analysis_947322335585c32a:block_9a5cbcb1178c50, analysis_947322335585c32a:block_795272fa53b168, analysis_947322335585c32a:block_cb7c55ac0e73ec, analysis_947322335585c32a:block_c35c25a231aeed, analysis_947322335585c32a:block_a562bb8e901a9e, analysis_947322335585c32a:block_29b982b4330a4f |
| c13 messages.py is a service/core candidate with 497 incoming and 102 outgoing calls. Its listed class blocks are BaseToolReturnPart, lines 2060-2391 at confidence 0.99, and ModelResponse, lines 4580-4862 at confidence 0.97. | inferred | supported | analysis_947322335585c32a:role_215, analysis_947322335585c32a:block_34ca40817a0242, analysis_947322335585c32a:block_bd059aeb4397d5 |
| c14 exceptions.py is a leaf/data-boundary candidate with 541 incoming and 0 outgoing calls. Its listed class blocks are RunCancelled, lines 344-520, and ModelHTTPError, lines 917-1092, both at confidence 0.97. | inferred | supported | analysis_947322335585c32a:role_195, analysis_947322335585c32a:block_9a5cbcb1178c50, analysis_947322335585c32a:block_795272fa53b168 |
| c15 _utils.py is a service/core candidate with 313 incoming and 6 outgoing calls. Its listed class blocks are PeekableAsyncStream, lines 722-827, and ScopedTask, lines 336-439, both at confidence 0.97. | inferred | supported | analysis_947322335585c32a:role_110, analysis_947322335585c32a:block_cb7c55ac0e73ec, analysis_947322335585c32a:block_c35c25a231aeed |
| c16 models/__init__.py is a service/core candidate with 165 incoming and 127 outgoing calls. Its listed class blocks are Model, lines 747-2140, and StreamedResponse, lines 2144-2456, both at confidence 0.99. | inferred | supported | analysis_947322335585c32a:role_216, analysis_947322335585c32a:block_a562bb8e901a9e, analysis_947322335585c32a:block_29b982b4330a4f |
| c17 The change-guide lesson lists six blocks with stronger static coupling. Three are in library code. Three are outside it, in tests/clai2/menu_script.py and .github/scripts/agentic_workflow_guard.py, so part of the coupling signal comes from test or tooling code. | inferred | supported | analysis_947322335585c32a:block_00b21f58abc199, analysis_947322335585c32a:block_60429d3e04e54a, analysis_947322335585c32a:block_38e439e8e58911, analysis_947322335585c32a:block_8cd2b3884eaae2, analysis_947322335585c32a:block_a332026144602f, analysis_947322335585c32a:block_ac673026a8a2f1 |
| c18 The library change-guide blocks are the UserError class block, the VercelAIAdapter.load_messages function block with 193 downstream relations, and a for block at lines 388-843 that repeats a region according to its loop condition or iterable. | inferred | supported | analysis_947322335585c32a:block_00b21f58abc199, analysis_947322335585c32a:block_60429d3e04e54a, analysis_947322335585c32a:block_38e439e8e58911 |
| c19 Outside library code, the lesson lists the function pick with 3 downstream relations and a straight_line block inside it. It also lists check_provider_health_monitor, with 225 downstream relations. | inferred | supported | analysis_947322335585c32a:block_8cd2b3884eaae2, analysis_947322335585c32a:block_a332026144602f, analysis_947322335585c32a:block_ac673026a8a2f1, analysis_947322335585c32a:py_func_f05e35e65daa, analysis_947322335585c32a:py_func_28485228aa29 |
| c20 tests/clai2/menu_script.py is a leaf/data-boundary candidate with 699 incoming calls, the highest incoming count in the module role list. | inferred | supported | analysis_947322335585c32a:role_451, analysis_947322335585c32a:role_450, analysis_947322335585c32a:role_195, analysis_947322335585c32a:role_215 |
| c21 The analysis is static only: reflection, runtime dependency injection, dynamic imports, monkey-patching, generated code, framework runtime wiring and dynamic dispatch are not resolved. | observed | supported | analysis_947322335585c32a:lim_1 |
| c22 Block descriptions are analyzer inferences carrying confidence values, such as 0.76 and 0.99, rather than runtime proof. | inferred | supported | analysis_947322335585c32a:block_e0cc5f8a441d6d, analysis_947322335585c32a:block_dbf176e51e7398 |
| c23 Install, run and build inference is partial and installation commands are not verified. | observed | supported | analysis_947322335585c32a:lim_2 |
| c24 Files over 400 kB, minified bundles and vendored directories are inventoried but not parsed; nine files were skipped this way. | inferred | supported | analysis_947322335585c32a:lim_6, analysis_947322335585c32a:claim_cc68ccd3be32 |
| c25 Relation extraction has a repository cap, and that cap was reached, so call counts and coupling signals may be incomplete. | inferred | supported | analysis_947322335585c32a:lim_6, analysis_947322335585c32a:claim_d827009928f8 |
| c26 Eight entrypoint paths have no statically detected call steps. | inferred | supported | analysis_947322335585c32a:claim_93f033d41d8d |
| c27 The uncertainties lesson lists no blocks. The analyzer's uncertainty records cover skipped files, a reached relation cap and entrypoint paths without detected call steps. | inferred | supported | analysis_947322335585c32a:claim_cc68ccd3be32, analysis_947322335585c32a:claim_d827009928f8, analysis_947322335585c32a:claim_93f033d41d8d |
Sources, rights and disclosure · attribution-license-templates/v0.1
Rights notice. Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.
Platform notice. GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.
How this page is produced. This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.
AI-assisted analysis. Reviewed by EVEMISS Technology through human–AI collaborative review. · Report a rights concern · Back to the overview