fix: exclude null file_id from input_image payload to prevent 400 sch…#5125
fix: exclude null file_id from input_image payload to prevent 400 sch…#5125Serjbory wants to merge 2 commits intomicrosoft:mainfrom
Conversation
|
Thanks for pushing this fix! |
giles17
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 94%
✓ Correctness
The fix correctly addresses the issue of sending
"file_id": nullto APIs (like Azure AI Foundry) that reject null values in the request payload. The implementation properly builds the base dict withoutfile_id, then conditionally adds it only when a non-None value is present. The test assertion is correctly updated to match the new behavior ("file_id" not in resultinstead ofresult["file_id"] is None). TheAnytype used in the newdict[str, Any]annotation is already imported. The a2a test changes are purely cosmetic reformatting with no functional impact. No correctness issues found.
✓ Security Reliability
This PR fixes a reliability issue where
"file_id": nullwas always included in the image content payload sent to the OpenAI/Azure AI Foundry Responses API, causing request rejections from services with strict schema validation. The fix conditionally includesfile_idonly when it has a non-None value, which is the correct approach and consistent with howfilenameis handled forinput_filecontent (lines 1360-1361 in the existing code). The test updates correctly verify the new behavior. The a2a test changes are whitespace-only reformatting with no functional impact. No security or reliability concerns found.
✗ Test Coverage
The code change correctly fixes the bug where
file_id: nullwas being sent in API payloads. The existing test at line 2274 is properly updated to assert"file_id" not in resultinstead ofresult["file_id"] is None, and the positive test case (line 2267) still validates thatfile_idis included when provided. However, there is a missing test for the edge case whereadditional_propertiesexists but does not contain afile_idkey (e.g.,{"detail": "high"}withoutfile_id), which is distinct from having noadditional_propertiesat all. The a2a test changes are purely formatting (no behavioral changes).
✓ Design Approach
The core fix correctly addresses the root cause:
"file_id": nullwas always serialized into the Responses API payload, causing rejection by stricter API validators (e.g., Azure AI Foundry). The fix conditionally includesfile_idonly when it has a real value, consistent with howfilenameandstatusare handled elsewhere in the same function. The test update correctly reflects the new contract. The a2a test changes are pure cosmetic reformatting with no behavioral impact. No design-level concerns remain.
Suggestions
- Add a test case for image content with
additional_propertiesthat has other keys but nofile_id(e.g.,additional_properties={"detail": "high"}). This exercises thecontent.additional_properties.get("file_id")returningNonepath whereadditional_propertiesis notNonebutfile_idis absent — a distinct code path from theadditional_properties is Nonecase already tested.
Automated review by giles17's agents
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
|
@giles17 thx for the review. I've added test for the mentioned edge case |
…ema error (#5120)
Motivation and Context
Using
Content.from_uri()with a base64 data URI to send images viaFoundryChatClient(Responses API path) results in a 400 error:"The provided data does not match the expected schema".This is a regression in 1.0.0 that breaks all inline image inputs through the Responses API client.
Description
The
_prepare_content_for_openaimethod inRawOpenAIChatClientunconditionally included"file_id": Nonein theinput_imagepayload dict. Because the framework passes raw dicts (not Pydantic models) to the OpenAI SDK,Nonevalues are not stripped during serialization —Nonebecomesnullon the wire:{"type": "input_image", "image_url": "data:image/jpeg;base64,...", "detail": "auto", "file_id": null}The API expects
file_idto be astringwhen present. Sendingnullviolates the schema and produces the 400 error.Fix: Only include
file_idin the dict when it has an actual value. Updated the corresponding test assertion fromfile_id is Nonetofile_id not in result.Contribution Checklist