anthropics / anthropics/anthropic-sdk-typescript

json_schema structured output truncates content at HTML tags containing quotation marks

Đang mở
#928 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
api
Ngôn ngữ chính
TypeScript
Star
2.1k
Fork
403
Merge trung bình
1 ngày 21 giờ
Pull request đã merge (30 ngày)
8

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.