fix: guard None text in text_message_output and add output guardrail count to RunErrorDetails#3377
Closed
zhoufengen wants to merge 1 commit into
Conversation
…ardrail count to RunErrorDetails pretty-print - ItemHelpers.text_message_output: apply the same `or ""` guard that extract_text already uses. Provider gateways (e.g. LiteLLM) and model_construct paths during streaming can surface None for ResponseOutputText.text; without the guard the concatenation raises TypeError. - pretty_print_run_error_details: add the missing output_guardrail_results line so RunErrorDetails.__str__ is consistent with pretty_print_result and pretty_print_run_result_streaming, which both report both guardrail counts. - Add tests/utils/test_pretty_print_and_items.py covering both fixes. - Update the existing inline snapshot in tests/test_pretty_print.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two small, related fixes in the SDK's output-handling utilities:
1.
ItemHelpers.text_message_output— guard againstNonetextextract_text(the sibling method in the same class) already applies anor ""guard with an explicit comment explaining that provider gateways (e.g. LiteLLM) andmodel_constructpaths during streaming can surfaceNoneforResponseOutputText.text.text_message_outputhad the same concatenation loop without the guard, so the sameTypeError: can only concatenate str (not "NoneType") to strcould fire throughtext_message_outputsandagent.py'stext_outputpath.Fix:
text += item.text or ""2.
pretty_print_run_error_details— include output guardrail countpretty_print_resultandpretty_print_run_result_streamingboth reportinput_guardrail_resultsandoutput_guardrail_results.pretty_print_run_error_detailsreported only the input count, soRunErrorDetails.__str__()silently omitted output guardrail results — misleading when an output guardrail is the reason the run failed.Fix: add the missing
output_guardrail_resultsline.Test plan
New file
tests/utils/test_pretty_print_and_items.py(5 tests):test_text_message_output_returns_empty_string_for_none_text— reproduces theTypeErroron the old code viamodel_constructtest_text_message_output_returns_text_normally— normal path still workstest_text_message_outputs_handles_none_text_across_items— multi-item list with aNoneentrytest_pretty_print_run_error_details_includes_output_guardrail_count— asserts both counts appeartest_pretty_print_run_error_details_zero_output_guardrails— zero caseUpdated inline snapshot in
tests/test_pretty_print.py::test_pretty_run_error_details.Full verification stack:
make format— no changesmake lint— all checks passedmake typecheck— mypy: no issues (767 files), pyright: 0 errorsmake tests(parallel + serial) — all passedIssue number
N/A (no existing issue; both are small, self-contained defects).
Checks
make lintandmake format