Skip to content

Commit 879d456

Browse files
fix(pydantic-ai): distinguish tool span outcomes (#1195)
## Summary Tool spans used to imply that a tool ran whenever a tool-call message existed. A `requires_approval=True` tool got a reconstructed `tool` span before it ran, and structured output / Model Router produced a misleading `final_result` tool span. This PR follows the instrumentation spec: - **Pending approval prompts** produce no tool span. - **Executed tools** get a live span. If approval is known, it records `metadata.tool_approval = "approved"`. Execution failures go in the top-level `error`. - **Concrete denials** record `metadata.tool_approval = "denied"`, with no output and no error. - **Deferred metadata** is no longer copied onto spans. - **Reconstructed spans** (`metadata.tool_outcome = "reconstructed"`) are built only when a matching return shows the tool executed or was denied. - **Structured output** stays on the model and agent spans and no longer creates a `tool` span. Also fixes direct `Agent.iter()` so it passes the agent span to the capture initializer. #1194 made that argument required, and without it the #1192 iter root span was missing for lineage. Tests replay VCR cassettes of real OpenAI Responses calls. They cover approval-only, mixed, streaming, denial and router cases, and use the Harness nox session. Version-specific hooks check that the feature exists, so pydantic-ai 1.107.9 still works. --------- Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent aa8d50e commit 879d456

10 files changed

Lines changed: 1512 additions & 53 deletions

‎py/src/braintrust/integrations/pydantic_ai/harness/cassettes/latest/test_declarative_tool_approval[approval-only].yaml‎

Lines changed: 250 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)