From f4b824524106a69c7363ff618aabf87d8ccd2ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 5 Mar 2026 14:55:31 -0800 Subject: [PATCH] Warn when both system_instruction and context system message are set system_instruction from the constructor always takes precedence. A warning is now logged when the context also contains a system message so users can spot the conflict. --- src/pipecat/services/anthropic/llm.py | 5 +++++ src/pipecat/services/aws/llm.py | 5 +++++ src/pipecat/services/openai/base_llm.py | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pipecat/services/anthropic/llm.py b/src/pipecat/services/anthropic/llm.py index 755ca6400..5981d3e50 100644 --- a/src/pipecat/services/anthropic/llm.py +++ b/src/pipecat/services/anthropic/llm.py @@ -403,6 +403,11 @@ class AnthropicLLMService(LLMService): context, enable_prompt_caching=self._settings.enable_prompt_caching ) if self._system_instruction: + if params["system"] is not NOT_GIVEN: + logger.warning( + f"{self}: Both system_instruction and a system message in context are" + " set. Using system_instruction." + ) params["system"] = self._system_instruction return params diff --git a/src/pipecat/services/aws/llm.py b/src/pipecat/services/aws/llm.py index 31f8085bc..e465ae460 100644 --- a/src/pipecat/services/aws/llm.py +++ b/src/pipecat/services/aws/llm.py @@ -1025,6 +1025,11 @@ class AWSBedrockLLMService(LLMService): adapter: AWSBedrockLLMAdapter = self.get_llm_adapter() params: AWSBedrockLLMInvocationParams = adapter.get_llm_invocation_params(context) if self._system_instruction: + if params["system"]: + logger.warning( + f"{self}: Both system_instruction and a system message in context are" + " set. Using system_instruction." + ) params["system"] = [{"text": self._system_instruction}] return params diff --git a/src/pipecat/services/openai/base_llm.py b/src/pipecat/services/openai/base_llm.py index ed012d0df..dfef1ae90 100644 --- a/src/pipecat/services/openai/base_llm.py +++ b/src/pipecat/services/openai/base_llm.py @@ -292,9 +292,14 @@ class BaseOpenAILLMService(LLMService): params.update(self._settings.extra) - # Prepend system instruction if set + # Prepend system instruction from constructor, replacing any context system message if self._system_instruction: messages = params.get("messages", []) + if messages and messages[0].get("role") == "system": + logger.warning( + f"{self}: Both system_instruction and a system message in context are set." + " Using system_instruction." + ) params["messages"] = [ {"role": "system", "content": self._system_instruction} ] + messages