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 摘要。