Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-anthropic, ai-gemini, ai-mistral, ai-ollama, ai-bedrock): report max-token truncation in structuredOutput #1548

Mergedkartsan03(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/1548/headmerged by AlemTuzlak View on GitHub

Showing 13 changed files with 53 additions and 0 deletions (loading 10).

x
0 of 13 viewed, 13 left
9 additions and 0 deletions.changeset/structured-output-truncation-other-adapters.mdAdded
View file
@@ -0,0 +1,9 @@
+---
+'@tanstack/ai-anthropic': patch
+'@tanstack/ai-gemini': patch
+'@tanstack/ai-mistral': patch
+'@tanstack/ai-ollama': patch
+'@tanstack/ai-bedrock': patch
+---
+​
+Structured output now reports a truncation error when the response stops at the output token limit. Before, you got a JSON parse error, or the partial result came back as valid data. `openai-base` and `ai-openrouter` already do this (#1426).
8 additions and 0 deletionspackages/ai-anthropic/src/adapters/text.tsModified
View file
@@ -480,6 +480,14 @@
​
+ // A forced tool call cut off at the output cap carries partial input,
+ // which would read like a schema failure (issue #1426).
+ if (response.stop_reason === 'max_tokens') {
+ throw new Error(
+ 'anthropic.structuredOutput: the response was cut off because the maximum token limit was reached (stop_reason=max_tokens); raise modelOptions.max_tokens',
+ )
+ }
+​
// Extract the tool use content from the response