Skip to content

fix: add JSON rule to Groq prompt to satisfy json_object requirement#104

Merged
Muizzkolapo merged 1 commit intomainfrom
fix/groq-json-mode-prompt-rule
Apr 2, 2026
Merged

fix: add JSON rule to Groq prompt to satisfy json_object requirement#104
Muizzkolapo merged 1 commit intomainfrom
fix/groq-json-mode-prompt-rule

Conversation

@Muizzkolapo
Copy link
Copy Markdown
Owner

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:

'messages' must contain the word 'json' in some form, to use 'response_format' of type 'json_object'.

Root cause

The TAGGED_GROQ prompt style in MessageBuilder._assemble_body() returned early (line 343) before reaching the rules injection point (line 362). So json_rules configured on the Groq provider were silently ignored.

Fix

  • Append rules inside the TAGGED_GROQ block before returning
  • Added json_rules=("RULES: Respond in valid JSON format.",) to Groq's ProviderMessageConfig — same pattern used by OpenAI, Mistral, Gemini, and Cohere

Test plan

  • pytest tests/unit/prompt/test_message_builder.py — 69 passed
  • Verified "json" appears in assembled Groq messages
  • Manual: run workflow with Groq + json_mode → no 400 error

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.
@Muizzkolapo Muizzkolapo merged commit 573de1d into main Apr 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant