Skip to content

fix(groq,google): suppress response format when tools are present#16540

Open
FrancoKaddour wants to merge 5 commits into
vercel:mainfrom
FrancoKaddour:fix/groq-google-response-format-tools-conflict
Open

fix(groq,google): suppress response format when tools are present#16540
FrancoKaddour wants to merge 5 commits into
vercel:mainfrom
FrancoKaddour:fix/groq-google-response-format-tools-conflict

Conversation

@FrancoKaddour

Copy link
Copy Markdown

Fixes #10023

Both Groq and Google APIs reject requests that combine a structured JSON response format with function calling tools:

  • Groq: "json mode cannot be combined with tool/function calling"
  • Google: "Forced function calling (ANY mode) with a response mime type: 'application/json' is unsupported"

Calling generateText() with both output (which sets responseFormat) and tools therefore throws a 400 on both providers.

Fix: In both providers, when tools are present they take precedence and the response format fields response_format for Groq, responseMimeTyperesponseSchema for Google) are omitted before the request is sent.

Recurse only through known JSON Schema structural keywords (properties,
patternProperties, \, allOf, anyOf, etc.) instead of every object key.
Prevents deletion of user-defined tool or response parameters whose name
happens to be 'pattern'.
…jection

When a tool call's input is not valid JSON, the catch block fallback
stored toolCall.input (a raw string) directly as the tool call's input
field. On multi-turn conversations this raw string ends up in the
message history. Providers like Amazon Bedrock expect toolUse.input to
be a JSON object and reject the request with a format error on the
next turn.

Fix: when safeParseJSON fails, store { rawInvalidInput: toolCall.input }
so the field is always a JSON-serialisable object.

Fixes vercel#14442
Both Groq and Google APIs reject requests that combine a structured JSON
response format (json_schema / application/json mime type) with function
calling tools. generateText() with output + tools therefore threw a 400
on both providers.

When tools are present they take precedence and the response format
fields are cleared before the request is sent.

Fixes vercel#10023
Comment thread packages/google/src/google-language-model.ts
Comment thread packages/groq/src/groq-chat-language-model.ts
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.

generateText() errors in v5 and v6 when using (experimental_)output

1 participant