From e9113bad33ce52c32956293f1ade98a99d62acba Mon Sep 17 00:00:00 2001 From: Anmol Jaiswal <68013660+anmolg1997@users.noreply.github.com> Date: Wed, 15 Apr 2026 08:58:35 +0530 Subject: [PATCH] fix(models): pass NOT_GIVEN instead of None for system instruction in AnthropicLlm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #5318 --- src/google/adk/models/anthropic_llm.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/google/adk/models/anthropic_llm.py b/src/google/adk/models/anthropic_llm.py index a14c767f23..79692fc367 100644 --- a/src/google/adk/models/anthropic_llm.py +++ b/src/google/adk/models/anthropic_llm.py @@ -402,10 +402,16 @@ async def generate_content_async( else NOT_GIVEN ) + system = ( + llm_request.config.system_instruction + if llm_request.config and llm_request.config.system_instruction + else NOT_GIVEN + ) + if not stream: message = await self._anthropic_client.messages.create( model=model_to_use, - system=llm_request.config.system_instruction, + system=system, messages=messages, tools=tools, tool_choice=tool_choice, @@ -431,9 +437,14 @@ async def _generate_content_streaming( a final aggregated LlmResponse with all content. """ model_to_use = self._resolve_model_name(llm_request.model) + system = ( + llm_request.config.system_instruction + if llm_request.config and llm_request.config.system_instruction + else NOT_GIVEN + ) raw_stream = await self._anthropic_client.messages.create( model=model_to_use, - system=llm_request.config.system_instruction, + system=system, messages=messages, tools=tools, tool_choice=tool_choice,