danielmiessler / danielmiessler/Fabric

Groq chat.completions rejects Fabric payload when pattern input becomes a system message (last role must be 'user')

Open
#2,108 1 comment 0 reactions 1 assignee Claimed by @ksylvan View on GitHub
Dominant language
Go
Stars
43.9k
Forks
4.3k
Avg merge
1d 4h
Merged PRs (30d)
8

Description

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
- Fabric CLI v1.4.451
- Groq vendor configured via ~/.config/fabric/.env (GROQ_API_BASE_URL=https://api.groq.com/openai/v1, DEFAULT_MODEL=groq/compound)

Reproduction
1. Ensure Groq config present in ~/.config/fabric/.env.
2. Run:

printf 'Test input for summary.' | fabric -p summarize --vendor Groq --model groq/compound --debug=4

3. 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.