fix: guard against None message in structured_output_response - #690
fix: guard against None message in structured_output_response#690qizwiz wants to merge 1 commit into
Conversation
…ed_output_response The existing checks test choices[0].message.content is None, but if message itself is None (returned by Gemini and some other providers on content-filtered responses with HTTP 200), the attribute access crashes with AttributeError before the guard can fire. Fix both sync and async paths to check message is None separately.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR tightens structured-output validation in OpenAI response handlers by splitting combined null checks into granular steps. Two methods— ChangesValidation Tightening for Structured OpenAI Responses
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Fix two places in
augmented_llm_openai.pywhere the existing guardis itself vulnerable to
AttributeErrorwhenmessageisNone.Why
If
completion.choices[0].messageisNone(e.g. Gemini via OpenAI-compatible endpoint on PROHIBITED_CONTENT, which returns HTTP 200 withmessage: null), accessing.contentin the condition itself throwsAttributeError: 'NoneType' object has no attribute 'content'— before the guard can fire.Fix
Both the sync and async
structured_output_responsepaths are fixed.No behaviour change for well-formed responses.
Summary by CodeRabbit