Title: Groq chat.completions rejects Fabric payload when pattern input becomes a system message (last role must be 'user')
Summary
Fabric can produce a chat payload containing only a system message (pattern instructions concatenated with the INPUT). Groq’s chat.completions API rejects this with: "last message role must be 'user'". That breaks many built-in patterns (e.g., summarize) when using the Groq vendor.
Environment
Reproduction
-
Ensure Groq config present in ~/.config/fabric/.env.
-
Run:
printf 'Test input for summary.' | fabric -p summarize --vendor Groq --model groq/compound --debug=4
-
Observe error and debug lines showing a single system message and the Groq response:
POST "https://api.groq.com/openai/v1/chat/completions": 400 Bad Request {"message":"last message role must be 'user'"}
Expected
When sending to chat.completions, the final message in the messages array should be role='user'. Fabric should either:
- Send patterns as separate messages (system + user) so the final message role is 'user', or
- Detect that Groq requires a user message and append a user message (e.g., with the input) before sending.
Suggested fix (minimal)
- In the Groq/OpenAI-compatible vendor adapter, when constructing the messages array:
- If messages currently end with role != 'user' (or there is only a system message), append a user message with the input content (or move the input into a final user message) before POST.
- Add unit/integration test covering a pattern that places the INPUT placeholder in system.md to ensure Groq chat requests always end with a user role.
Optional notes
- Many patterns place the INPUT marker in system.md by design; the adapter should be robust to that by ensuring the last message role is 'user' for chat endpoints.
I can provide debug logs and the summarize pattern files on request.
Title: Groq chat.completions rejects Fabric payload when pattern input becomes a system message (last role must be 'user')
Summary
Fabric can produce a chat payload containing only a system message (pattern instructions concatenated with the INPUT). Groq’s chat.completions API rejects this with: "last message role must be 'user'". That breaks many built-in patterns (e.g., summarize) when using the Groq vendor.
Environment
Reproduction
Ensure Groq config present in ~/.config/fabric/.env.
Run:
printf 'Test input for summary.' | fabric -p summarize --vendor Groq --model groq/compound --debug=4
Observe error and debug lines showing a single system message and the Groq response:
POST "https://api.groq.com/openai/v1/chat/completions": 400 Bad Request {"message":"last message role must be 'user'"}
Expected
When sending to chat.completions, the final message in the messages array should be role='user'. Fabric should either:
Suggested fix (minimal)
Optional notes
I can provide debug logs and the summarize pattern files on request.