Add JSON response format support and dynamic model fetching#36
Closed
ttlequals0 wants to merge 4 commits intoRichardAtCT:mainfrom
Closed
Add JSON response format support and dynamic model fetching#36ttlequals0 wants to merge 4 commits intoRichardAtCT:mainfrom
ttlequals0 wants to merge 4 commits intoRichardAtCT:mainfrom
Conversation
- Add response_format parameter for OpenAI-compatible JSON mode - Add ModelService for dynamic model fetching from Anthropic API - Add claude-opus-4-5-20251101 model to supported models - Add JSON extraction and enforcement methods to MessageAdapter - Update docker-compose.yml to use published image - Bump version to 2.3.0
Claude Code SDK was ignoring JSON_MODE_INSTRUCTION in the system prompt and returning conversational text instead of JSON. Added JSON_PROMPT_SUFFIX constant that is now appended to the user prompt alongside the system prompt instruction, ensuring the model follows JSON output requirements. Changes: - Add JSON_PROMPT_SUFFIX constant to message_adapter.py - Append suffix to user prompt in both streaming and non-streaming paths - Update log messages to reflect dual-prompt approach - Bump version to 2.3.1
- Updated JSON_MODE_INSTRUCTION with explicit first/last character rules - Added explicit prohibition of markdown code blocks in instructions - Updated JSON_PROMPT_SUFFIX with more concise output format - Added log_json_structure() helper for debugging JSON responses - Added boundary and structure logging in streaming/non-streaming paths
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
response_format: {"type": "json_object"}parameter for JSON modeChanges
JSON Response Format
response_formatparameter in chat completions endpointstrict=Truemode returning[]on failureDynamic Model Fetching
ModelServiceclass fetches available models from Anthropic APIImproved JSON Instructions
Test plan
response_format: {"type": "json_object"}requestRaw response: starts=...without markdownJSON array with N itemsorJSON object fieldsin debug outputGenerated with Claude Code