Skip to content

fix(pydantic-ai): don't log deferred tool calls as errors - #975

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi/sdk-581-pydantic-ai-integration-deferred-tool-calls-incorrectly
Oct 19, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi/sdk-581-pydantic-ai-integration-deferred-tool-calls-incorrectly

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Fixes https://linear.app/braintrustdata/issue/SDK-581

Supersedes #969 (thanks to Ethan Leifer (@ethanleifer) for the PR)

AI Summary

Pydantic AI tools that raise CallDeferred or ApprovalRequired were logged as failed tool spans, even though these exceptions are Pydantic AI's normal way to defer a call or request human approval. Real failures show up as errors on the tool span, so deferred calls were tripping monitoring and alerting.

How this differs from #969

#969 This PR
Where the deferral is recorded output={"deferred": True, "reason": "<ExceptionName>"} metadata.deferred (+ deferred_metadata)
Fallback for Pydantic AI without these exceptions ImportError fallback not needed: the integration's min_version is 1.10.0, which has both
Reference to the re-raised exception kept cleared after re-raise, to avoid an exception → traceback → frame reference cycle

🤖 Generated with Claude Code

Tools raising CallDeferred or ApprovalRequired hand the call back to the
caller as DeferredToolRequests. That is control flow, not a failure, but
the tool span recorded it as an error. Catch both inside the span, log
the deferral kind (and CallDeferred/ApprovalRequired metadata when
present) on the span, and re-raise after the span closes.

Fixes SDK-581

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T17:50:26.721096Z d94c185 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 75a3c92 into main Oct 19, 2026
98 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi/sdk-581-pydantic-ai-integration-deferred-tool-calls-incorrectly branch October 19, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants