anthropics / anthropics/claude-agent-sdk-python

[BUG] StructuredOutput tool wraps data in 'output' field causing schema validation to fail

未關閉
#502 16 則留言 10 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
8.1k
分支
1.3k
平均合併
2 天 31 分鐘
30 天內合併 PR
1

描述

## Bug Description

When using structured outputs with `output_format`, the `StructuredOutput` tool **intermittently** wraps user data in an `{"output": {...}}` field. Validation fails when the wrapper is present.

**This is non-deterministic** - same prompt can produce either format:

```json
// Sometimes (works):
{"actions": [...]}

// Sometimes (fails validation):
{"output": {"actions": [...]}}
```

## Impact

1. `ResultMessage.structured_output` is `None` when wrapper is present
2. **Agent confusion** - Claude sees conflicting validation errors and may simplify output (e.g., 47 items → 1 item)
3. **Flaky results** - identical prompts succeed or fail randomly

## Tool Response Error

```
Output does not match required schema: root: must have required property 'actions', root: must NOT have additional properties
```

This error confuses Claude because:
- `actions` is "required" but exists inside `output`
- Schema has `additionalProperties: false`, so `output` is invalid

Claude tried to "debug" by reducing output from 47 items to 1 item.

## Environment

- claude-agent-sdk==0.1.19
- Python 3.11+

## Related

- #374 - Structured outputs flaky (similar wrapper issues with `properties`/`parameters`)

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。