Skip to content

fix(pydantic-ai): Only use hooks when ModelRequestContext.model exists#6480

Merged
alexander-alderman-webb merged 8 commits into
masterfrom
webb/pydantic-ai/hooks-version-gate
Jun 2, 2026
Merged

fix(pydantic-ai): Only use hooks when ModelRequestContext.model exists#6480
alexander-alderman-webb merged 8 commits into
masterfrom
webb/pydantic-ai/hooks-version-gate

.

4dbb8bf
Select commit
Loading
Failed to load commit list.
@sentry/warden / warden completed Jun 2, 2026 in 6m 10s

2 issues

Medium

`are_request_hooks_available` not reset to `False` when version < 1.73 but `Hooks` is importable - `sentry_sdk/integrations/pydantic_ai/__init__.py:12`

When pydantic-ai-slim is installed at a version < 1.73 but the Hooks class can be imported, setup_once() calls _patch_graph_nodes() and returns without registering hooks — but are_request_hooks_available remains True. This causes agent_run.py wrappers (lines 112, 161) to inject {"_sentry_span": None} into every agent run's metadata even though no hook will ever populate that span. Consider setting PydanticAIIntegration.are_request_hooks_available = False before returning in the version-check branch.

Also found at:

  • sentry_sdk/integrations/pydantic_ai/__init__.py:183-184

Low

Missing `_patch_graph_nodes()` fallback when `Hooks is None` at version >= 1.73 - `sentry_sdk/integrations/pydantic_ai/__init__.py:186-187`

When pydantic-ai-slim version is >= 1.73 but Hooks fails to import, the function returns silently without calling _patch_graph_nodes(), so model request spans are never captured. Before this change, Hooks is None always fell back to _patch_graph_nodes().

4 skills analyzed
Skill Findings Duration Cost
security-review 0 3.9s $0.01
code-review 1 3m 51s $0.54
find-bugs 1 5m 36s $0.53
skill-scanner 0 3.6s $0.01

⏱ 9m 34s · 459.9k in / 30.9k out · $1.08