Raise a clear error for list-form system_prompt#1087
Open
PranavMishra28 wants to merge 2 commits into
Open
Conversation
A list-of-content-blocks system_prompt was accepted at construction but crashed later in SubprocessCLITransport._build_command with a cryptic 'list' object has no attribute 'get' AttributeError. Validate the shape in ClaudeAgentOptions.__post_init__ and raise an actionable ValueError that names the concatenation workaround and its prompt-caching cost. The bundled CLI forwards the system prompt as plain text only, so full list-form support (per-block cache_control) needs a CLI-side flag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
simple fix for our sdk to immediately raise clear errors if a list is incorrectly passed in the system prompt |
tapheret2
reviewed
Jul 10, 2026
tapheret2
left a comment
There was a problem hiding this comment.
Review: Raise a clear error for list-form system_prompt
Files: src/claude_agent_sdk/types.py, tests/test_types.py
Size: +30 / -0
Notes
- Tests/fixtures included — good for merge confidence.
Nits
- Any user-facing change that should be mentioned in the PR description?
- Need a changelog/release note for the next tag?
Thanks @PranavMishra28 — independent review pass on the diff.
Author
|
@tapheret2 I've added the release note entry. Lemme know if you need any other fixes so we can get this merged in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
ClaudeAgentOptions(system_prompt=[...])(a list of Anthropic content blocks) was accepted at construction but then crashed later, at command-build time, with a crypticAttributeError: 'list' object has no attribute 'get'inSubprocessCLITransport._build_command. The failure was delayed and noisy — per the issue it surfaced only after a paid model call was already in flight.Why it matters
The Messages API
systemparameter acceptsstring | content_block[], and Anthropic's prompt-caching guidance recommends the list form socache_controlcan sit on a trailing block and give layer-independent caching (a stable role prompt vs. per-call injected content).Why this is a fast-fail, not full list-form support
The bundled
claudeCLI has no channel that carries a structuredsystemarray. Checking the bundled CLI (2.1.201): content passed via--system-prompt/--system-prompt-fileis forwarded as a single plain-text block, so a JSON array written to the file is sent verbatim as the literal system-prompt text and per-blockcache_controlis never honored. Real list-form support therefore needs a new CLI-side flag (one that forwards a JSONsystemarray to the API) and is out of scope for an SDK-only change.What the fix does
Validates the shape early, in
ClaudeAgentOptions.__post_init__: a listsystem_promptnow raises a clear, actionableValueErrorat construction — naming the concatenate-to-string workaround and its prompt-caching cost, and pointing to the preset/file forms — instead of the delayedAttributeError.What it deliberately does not change
str,None,SystemPromptPreset, andSystemPromptFileare untouched.Testing
ValueErrorat construction.system_prompttests (str / None / preset / preset+append / preset+exclude_dynamic / file) still pass.1057 passed, 5 skipped;ruff check,ruff format --check, andmypy --strict src/all clean.Addresses #899.
Developed with Claude Code; reviewed and tested by Pranav before marking ready for review.