Skip to content

fix(anthropic): omit null system field in streaming payload (parity with chat)#602

Merged
ilvalerione merged 1 commit into
neuron-core:3.xfrom
campbellking:fix/anthropic-stream-null-system
Jul 15, 2026
Merged

fix(anthropic): omit null system field in streaming payload (parity with chat)#602
ilvalerione merged 1 commit into
neuron-core:3.xfrom
campbellking:fix/anthropic-stream-null-system

Conversation

@campbellking

Copy link
Copy Markdown
Contributor

Problem

HandleChat sets system conditionally, but the Anthropic streaming path still sends the field unconditionally — src/Providers/Anthropic/HandleStream.php:

'system' => $this->system ?? null,

GuzzleHttpClient::runRequest passes the body verbatim via RequestOptions::JSON, so an agent with no system prompt sends "system": null, which the Anthropic Messages API rejects with a validation error. Streaming without a system prompt is therefore impossible on the Anthropic provider.

Fix

Mirror the chat path's conditional:

...($this->system !== null ? ['system' => $this->system] : []),

A possible follow-up (happy to include here if you'd like): the stream path also ignores systemPromptBlocks, while chat now has a systemBlocks branch — mirroring that would give streaming full parity with chat for prompt-caching users.

Reproduction

Call stream() on an Anthropic agent with no system prompt and inspect the outgoing request payload / API error response.

Context

Carried as a downstream composer patch since v3.3.10; applies cleanly to current 3.x.

…ith chat)

HandleChat sets 'system' conditionally, but HandleStream still sends
'system' => null when no system prompt is set. The request body is passed
verbatim as JSON, and the Anthropic Messages API rejects "system": null
with a validation error, making no-system streaming impossible. Mirror the
chat path's conditional spread.
@ilvalerione ilvalerione merged commit cc200b4 into neuron-core:3.x Jul 15, 2026
12 checks passed
@ilvalerione

Copy link
Copy Markdown
Contributor

Don't care about systemBlocks, it will be completely changed in v4.

Thank you for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants