Skip to content

fix(models): pass NOT_GIVEN instead of None for system instruction in AnthropicLlm#5337

Open
anmolg1997 wants to merge 1 commit intogoogle:mainfrom
anmolg1997:fix/anthropic-system-none
Open

fix(models): pass NOT_GIVEN instead of None for system instruction in AnthropicLlm#5337
anmolg1997 wants to merge 1 commit intogoogle:mainfrom
anmolg1997:fix/anthropic-system-none

Conversation

@anmolg1997
Copy link
Copy Markdown
Contributor

Summary

When no system instruction is set (e.g. during event compaction via LlmEventSummarizer), llm_request.config.system_instruction is None. The Anthropic API rejects None for the system parameter — it expects either a str, a list of content blocks, or the parameter to be omitted entirely. This causes a 400 Bad Request crash whenever compaction fires on a Claude model.

Changes

src/google/adk/models/anthropic_llm.py

  • In generate_content_async (non-streaming path): extract system before the API call, using NOT_GIVEN (already imported) when system_instruction is None or empty
  • In _generate_content_streaming: same fix for the streaming code path

How to reproduce

  1. Configure an ADK app with a Claude model (via Vertex AI) and EventsCompactionConfig
  2. Run enough invocations to trigger compaction (e.g. compaction_interval=20)
  3. Compaction fires → LlmEventSummarizer creates an LlmRequest with no system instruction → system=None → 400

Testing

  • Verified that NOT_GIVEN is already used in the same file for tools and tool_choice parameters, so this follows the established pattern
  • When system_instruction is a valid string, behavior is unchanged

Fixes #5318

… AnthropicLlm

When no system instruction is set (e.g. during event compaction),
system_instruction is None. The Anthropic API rejects None — it
expects a str or list of content blocks. This causes a 400 Bad
Request when compaction fires via LlmEventSummarizer.

Pass NOT_GIVEN (already imported) when system_instruction is
None/empty so the parameter is omitted from the API call. Fixes
both streaming and non-streaming code paths.

Fixes google#5318
@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 15, 2026
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