refactor: improve error messages and metadata handling#39
refactor: improve error messages and metadata handling#39Kamilbenkirane merged 2 commits intomainfrom
Conversation
- Update constraint error messages to include length and value details - Fix test expectations to match improved error message format - Refactor metadata handling to filter content fields before storing raw_response - Add content field filtering in provider clients (Anthropic, Cohere, Google, Mistral, OpenAI) - Improve error message formatting using !r for better debugging - Clean up comments and improve code consistency
Pull Request ReviewThis PR makes solid improvements to error messaging and metadata handling. The changes are well-tested and the CI passes. Here's my detailed feedback: ✅ Strengths
🔍 Potential Issues1. Incomplete Metadata RefactoringSeverity: Medium The # packages/text-generation/src/celeste_text_generation/client.py:66-72
def _build_metadata(self, response_data: dict[str, Any]) -> dict[str, Any]:
metadata = super()._build_metadata(response_data)
metadata["raw_response"] = (
response_data # Complete raw response (providers filter content fields)
)
return metadataProblem: The comment says "providers filter content fields" but Impact:
Recommendation: # Option 1: Store the filtered data that comes from super()
def _build_metadata(self, response_data: dict[str, Any]) -> dict[str, Any]:
metadata = super()._build_metadata(response_data)
# Note: Providers should pass filtered response_data
metadata["raw_response"] = response_data
return metadata
# Option 2: Document that raw_response contains full response
def _build_metadata(self, response_data: dict[str, Any]) -> dict[str, Any]:
metadata = super()._build_metadata(response_data)
metadata["raw_response"] = response_data # Unfiltered complete response
return metadataThe current implementation appears to defeat the purpose of filtering in providers since the unfiltered response is stored anyway. 2. Removed Finish Reason LogicSeverity: Medium In # OLD:
if "finish_reason" not in metadata:
finish_reason = self._parse_finish_reason(response_data)
if finish_reason is not None:
metadata["finish_reason"] = finish_reasonThis was removed entirely. Looking at the base class return self._output_class()(
finish_reason=self._parse_finish_reason(response_data),
...
)Questions:
Recommendation: Verify that finish_reason is still correctly parsed for image generation, especially for Google provider which has custom logic in 3. Minor: Inconsistent PrecisionSeverity: Low
f"[{self.min_aspect_ratio:.3f}, {self.max_aspect_ratio:.3f}]"Good catch fixing the inconsistent 🎯 Code Quality Observations
🔒 Security & PerformanceSecurity: ✅ No concerns
Performance: ✅ No concerns
🧪 TestingCoverage: ✅ Excellent
Suggestions:
📋 Recommendations SummaryMust Address:
Should Address: Nice to Have: 🎖️ Overall AssessmentRating: Approve with Minor Changes This is a solid refactoring that improves developer experience with better error messages and cleaner code. The architecture is sound, tests pass, and the changes are well-scoped. The main concern is ensuring the metadata filtering actually works as documented - this appears to be a logic issue where unfiltered data is stored despite the filtering effort in providers. Great work on the comprehensive testing and attention to error message quality! 🚀 Generated by Claude Code |
Remove comment that incorrectly implied raw_response contains complete unfiltered response. The response_data parameter is already filtered by providers before calling super()._build_metadata().
PR Review: Improve Error Messages and Metadata HandlingSummaryThis PR makes two main improvements: enhancing error messages with better debugging information and refactoring metadata handling to filter content fields from raw_response. Overall, the changes are well-implemented and improve code quality. Strengths
Issues and Concerns1. Inconsistent Metadata Filtering Logic (Medium Priority)The metadata filtering implementation may not work as intended. The base TextGenerationClient._build_metadata() receives response_data from the generate() method which is the unfiltered response. It then stores this unfiltered data as raw_response. The provider clients filter the data before calling super(), but this only affects what the base Client._build_metadata() sees, not what TextGenerationClient._build_metadata() stores. Impact: The raw_response in metadata may still contain content fields, defeating the purpose of the refactoring. Recommendation: Verify that the filtering actually works end-to-end. Consider storing the filtered data explicitly in provider clients after calling super(). 2. Finish Reason Handling Removed (Medium Priority)In packages/image-generation/src/celeste_image_generation/client.py:66-72, the previous logic that parsed finish_reason has been completely removed. The finish_reason is no longer being stored in metadata. Looking at the generate() method in src/celeste/client.py:70, the finish reason is passed to the Output constructor, but it's not clear if it's also needed in metadata for some providers or use cases. Questions: Was finish_reason in metadata redundant? Are there any consumers of metadata that expect finish_reason? Security Considerations
Performance Considerations
Testing
Suggestion: Consider adding a test to verify that content fields are actually filtered from metadata raw_response in the provider clients. RecommendationsHigh Priority: Verify metadata filtering actually works end-to-end Medium Priority: Document or verify finish_reason removal - ensure this is not a breaking change Low Priority: Improve or remove redundant comments Overall AssessmentCode Quality: 4/5 Recommendation: Approve with minor revisions - The changes are solid, but please verify the metadata filtering is working as intended. The error message improvements are excellent and ready to merge. Great work on improving the debugging experience! |
Summary
This PR improves error message formatting and refactors metadata handling across the codebase.
Changes
!rfor better debugging and cleaned up commentsTesting
Impact