anthropics / anthropics/anthropic-sdk-typescript
json_schema structured output truncates content at HTML tags containing quotation marks
- 主要語言
- TypeScript
- 星號
- 2.1k
- 分支
- 403
- 平均合併
- 1 天 21 小時
- 30 天內合併 PR
- 8
描述
This is an actual issue with the Anthropic API or other downstream services, but I'm reporting it here.
## Description
When using json_schema structured output with claude-sonnet-4-6, the model prematurely ends generation (stop_reason: "end_turn") when the content being written into a JSON string field contains HTML tags with quoted attribute values followed by quoted text — specifically tags wrapping quoted speech.
The model produces ~300 tokens and valid JSON, but the string value inside the body field is truncated mid-article. This reproduces 100% of the time with the curl below.
## Reproduction
```
curl -s https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 16000,
"temperature": 0.7,
"system": "You are a wildlife journalist. Use
for paragraphs,
for headings, for emphasis.",
"messages": [{"role": "user", "content": "Write a 500-word article about North American beaver population recovery. Include these three
expert quotes wrapped in cite tags exactly as shown:\n\n1. \"The beaver population has exceeded our
wildest expectations\"\n2. \"Beavers are nature s engineers — they create wetland ecosystems
that benefit hundreds of other species\"\n3. \"We are cautiously optimistic about long-term
sustainability\"\n\nInclude all three quotes verbatim inside their tags.\n\n=== OUTPUT FORMAT ===\n- success: true/false\n-
body: The HTML article with inline tags\n- reason: null if success"}],
"output_config": {
"effort": "low",
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"success": {"type": "boolean"},
"body": {"type": ["string", "null"]},
"reason": {"type": ["string", "null"]}
},
"required": ["success", "body", "reason"],
"additionalProperties": false
}
}
}
}' | jq '{stop_reason, output_tokens: .usage.output_tokens, body_tail: (.content[0].text | fromjson | .body | .[-100:])}'
```
### Expected
800 output tokens, complete 500-word article with all three tags and their quoted content.
### Actual
~300 output tokens, article truncates at the first
800 output tokens, complete 500-word article with all three tags and their quoted content.
~300 output tokens, article truncates at the first
貢獻指南
評估
這個 Issue 還沒有評估資料。