anthropics / anthropics/claude-agent-sdk-python

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

Offen
#502 16 Kommentare 10 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
8.1k
Forks
1.3k
Ø Merge
2 T. 31 Min.
Gemergte PRs (30 T.)
1

Beschreibung

## 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`)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.