Skip to content

fix: omit system parameter when None in AnthropicLlm#5335

Open
voidborne-d wants to merge 2 commits intogoogle:mainfrom
voidborne-d:fix/anthropic-system-none
Open

fix: omit system parameter when None in AnthropicLlm#5335
voidborne-d wants to merge 2 commits intogoogle:mainfrom
voidborne-d:fix/anthropic-system-none

Conversation

@voidborne-d
Copy link
Copy Markdown

Summary

Fixes #5318.

AnthropicLlm.generate_content_async passes system=None to the Anthropic API when no system instruction is set (e.g. when LlmEventSummarizer triggers event compaction). The Anthropic API rejects None — it expects either a str, a list of content blocks, or the parameter to be omitted entirely.

Changes

  • Compute system_instruction once before the stream/non-stream branch: use the config value when present, otherwise NOT_GIVEN (which the Anthropic SDK treats as "omit this parameter").
  • Pass the resolved value through to both the non-streaming messages.create call and the streaming helper _generate_content_streaming.
  • No behavioral change when a system instruction is provided.

Reproduction

  1. Configure an ADK app with a Claude model (via Vertex AI) and EventsCompactionConfig.
  2. Run enough invocations to trigger compaction.
  3. LlmEventSummarizer creates an LlmRequest with config.system_instruction = None.
  4. Before this fix: 400 Bad Requestsystem: Input should be a valid list.
  5. After this fix: compaction succeeds; the system parameter is omitted from the API call.

When system_instruction is None (e.g. during event compaction via
LlmEventSummarizer), the Anthropic API rejects system=None with a
400 Bad Request. Use NOT_GIVEN instead so the parameter is omitted
from the API call entirely.

Fixes google#5318
@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 15, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 15, 2026

Response from ADK Triaging Agent

Hello @voidborne-d, thank you for submitting this pull request!

To ensure code quality and prevent future regressions, could you please add a unit test that covers the case where system_instruction is None? You can find more information about testing requirements in our contribution guidelines.

Thanks!

Adds two tests covering the fix for google#5318:
- test_generate_content_async_none_system_instruction_non_streaming
- test_generate_content_async_none_system_instruction_streaming

Both verify that system=NOT_GIVEN (not None) is passed to the Anthropic
API when system_instruction is unset, preventing 400 Bad Request errors
during event compaction.
@voidborne-d
Copy link
Copy Markdown
Author

Thanks for the review! I've added two unit tests in 7ccb1c9:

  • test_generate_content_async_none_system_instruction_non_streaming — verifies system=NOT_GIVEN is passed (not None) when system_instruction is unset in the non-streaming path.
  • test_generate_content_async_none_system_instruction_streaming — same verification for the streaming path.

Both follow the existing patterns in test_anthropic_llm.py and assert that the Anthropic API receives NOT_GIVEN instead of None, which prevents the 400 Bad Request from #5318.

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

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnthropicLlm.generate_content_async passes system=None to Anthropic API, causing 400 during event compaction

2 participants