Skip to content

fix: complete tool messages to the shape strict providers require - #457

Open
WSHAPER wants to merge 2 commits into
nextcloud:mainfrom
WSHAPER:fix/tool-message-name
Open

WSHAPER wants to merge 2 commits into
nextcloud:mainfrom
WSHAPER:fix/tool-message-name

Conversation

@WSHAPER

@WSHAPER WSHAPER commented Oct 30, 2026

Copy link
Copy Markdown

Fixes #456

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

Chat-with-tools requests broke with a 400 "Provider returned error" on
providers that validate the request strictly (Groq via OpenRouter serving
openai/gpt-oss-120b: "'messages.3' : for 'role:tool' the following must
be satisfied [('messages.3.name' : Value is not nullable)]"). Two sites
sent role:tool messages in a shape such validators reject:

- requestChatCompletion passed the current-turn tool results through
  with the incoming "name": null. Groq's schema makes name optional but
  non-nullable, so an explicit null fails validation.
- the history loop passed role:tool entries through with no name and no
  tool_call_id at all, while Groq requires tool_call_id on every tool
  message.

Resolve the function name of each tool result from the assistant
tool_calls already present in the conversation (falling back to a
generic name when the id cannot be matched) and complete history tool
entries with the name and tool_call_id of the assistant call they
answer. The corrected request was verified accepted by a live Groq
backend through OpenRouter: the model responded with a tool call.

Assisted-by: opencode (zai/glm-5.3)
Signed-off-by: WSHAPER <42714629+WSHAPER@users.noreply.github.com>
The tool message contract is a single message object (see the parameter
documentation and the chat-with-tools task input), but the name
completion iterated the decoded value as a list. Iterating a bare
object yields its field values, so the first loop pass received the
role field's string and the array access on it raised a TypeError. The
decoded value is now normalized to a list, so the single-object
contract works and a list stays accepted defensively.

Assisted-by: opencode (zai/glm-5.3)
Signed-off-by: WSHAPER <42714629+WSHAPER@users.noreply.github.com>
@marcelklehr
marcelklehr requested a review from julien-nc November 3, 2026 15:54

This branch has not been deployed

No deployments
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.

Chat with tools fails with 400 on strictly validating providers (Groq via OpenRouter): role:tool messages lack name / tool_call_id

1 participant