Integrate Improved Structured Outputs in the Gemini API#48
Integrate Improved Structured Outputs in the Gemini API#48Kamilbenkirane merged 1 commit intomainfrom
Conversation
- Update to use responseJsonSchema parameter (correct API name) - Remove resolution code - API now supports natively - Preserve at root level for list schemas to support references - Support expanded JSON Schema features: anyOf, minimum/maximum, additionalProperties, prefixItems
PR Review: Integrate Improved Structured Outputs in the Gemini APISummaryThis PR makes critical updates to align with Google's improved structured outputs API. The changes are well-motivated and the code quality is generally good. ✅ Positive Changes1. Correct API Parameter Name (parameters.py:117)
2. Simplified Implementation
3. Proper $defs Handling for Arrays (parameters.py:143-148)
🔍 Code Quality ObservationsGood Practices
Areas for Consideration1. Test Coverage 🔴 HIGH PRIORITYIssue: No unit tests found for the OutputSchemaMapper class
Recommendation: Add test cases for:
2. Potential Edge Cases 🟡 MEDIUM PRIORITYWhat if items_schema has nested $defs inside properties? What if there are $defs name collisions between different models? Should there be validation that defs is a dict? Example: If BaseModel has nested models, list[Person] where Person contains Address should work, but needs testing. 3. Missing Validation 🟡 MEDIUM PRIORITYNo validation that:
4. Documentation Gap 🟡 MEDIUM PRIORITY
🔒 Security Analysis✅ No security concerns identified
⚡ Performance Considerations✅ Performance improved
📋 Recommendations Summary
✅ Approval StatusCode Quality: ✅ Good Recommendation: Approve with suggestions - The core changes are solid and necessary. However, adding tests would significantly increase confidence in the implementation, especially for the $defs extraction logic. Great work on simplifying this implementation! The removal of _resolve_refs() is a significant improvement. |
This PR integrates the improved structured outputs features announced in the Gemini API blog post (Nov 2025).
Changes
responseSchematoresponseJsonSchema(correct API parameter name)_resolve_refs()method since the API now supports `` nativelyat root level when creating array schemas from `list[BaseModel]` to supportreferencesanyOffor conditional structures (Unions)minimumandmaximumfor numeric constraintsadditionalPropertiesandtype: 'null'prefixItemsfor tuple-like arraysRelated