fix: add JSON rule to Groq prompt to satisfy json_object requirement#104
Merged
Muizzkolapo merged 1 commit intomainfrom Apr 2, 2026
Merged
fix: add JSON rule to Groq prompt to satisfy json_object requirement#104Muizzkolapo merged 1 commit intomainfrom
Muizzkolapo merged 1 commit intomainfrom
Conversation
Groq's API requires the word "json" to appear in the messages when response_format is set to json_object. The TAGGED_GROQ prompt style was returning early before the rules injection point, so json_rules were never appended. Fix: append rules inside the TAGGED_GROQ block before returning. Added "RULES: Respond in valid JSON format." to Groq's provider config, matching the pattern used by OpenAI, Mistral, and Gemini.
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
Groq's API requires the word "json" to appear somewhere in the messages when
response_format: {"type": "json_object"}is set. Without it, every request fails with:Root cause
The
TAGGED_GROQprompt style inMessageBuilder._assemble_body()returned early (line 343) before reaching the rules injection point (line 362). Sojson_rulesconfigured on the Groq provider were silently ignored.Fix
TAGGED_GROQblock before returningjson_rules=("RULES: Respond in valid JSON format.",)to Groq'sProviderMessageConfig— same pattern used by OpenAI, Mistral, Gemini, and CohereTest plan
pytest tests/unit/prompt/test_message_builder.py— 69 passed