From 8fe9257f6f7c98c812d6aaec7cf56eb10075cf1e Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Mon, 31 Aug 2026 15:10:43 -0400 Subject: [PATCH 1/3] test(pydantic_ai): Fix instructions test for pydantic-ai >=2.36.0 Build the agent with public `instructions`/`system_prompt` kwargs instead of poking internal `_instructions`/`_system_prompts` attributes, and account for the joiner between multiple instructions changing from a single newline to a blank line in pydantic-ai 2.36.0. Fixes PY-2755 Fixes #7306 --- tests/integrations/pydantic_ai/test_pydantic_ai.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index e6cbf699df..ccff7d6a1f 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -2228,15 +2228,16 @@ async def test_invoke_agent_with_instructions( """ from pydantic_ai import Agent - # Create agent with instructions (can be string or list) + # Create agent with instructions (can be string or list) and system prompt agent = Agent( "test", name="test_instructions", + instructions=["Instruction 1", "Instruction 2"], + system_prompt="System prompt", ) - # Add instructions via _instructions attribute (internal API) - agent._instructions = ["Instruction 1", "Instruction 2"] - agent._system_prompts = ["System prompt"] + # pydantic-ai >=2.36.0 joins multiple instructions with a blank line, earlier versions with a single newline + instructions_separator = "\n\n" if PYDANTIC_AI_VERSION >= (2, 36) else "\n" sentry_init( integrations=[PydanticAIIntegration(include_prompts=include_prompts)], @@ -2268,7 +2269,7 @@ async def test_invoke_agent_with_instructions( ] assert json.loads(system_instructions) == [ {"type": "text", "content": "System prompt"}, - {"type": "text", "content": "Instruction 1\nInstruction 2"}, + {"type": "text", "content": f"Instruction 1{instructions_separator}Instruction 2"}, ] else: assert SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS not in chat_span["attributes"] @@ -2291,7 +2292,7 @@ async def test_invoke_agent_with_instructions( system_instructions = chat_span["data"][SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS] assert json.loads(system_instructions) == [ {"type": "text", "content": "System prompt"}, - {"type": "text", "content": "Instruction 1\nInstruction 2"}, + {"type": "text", "content": f"Instruction 1{instructions_separator}Instruction 2"}, ] else: assert SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS not in chat_span["data"] From 28a901fd0afb8f87b7f4f1ef7f0aabb6956f44b4 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Mon, 31 Aug 2026 15:13:25 -0400 Subject: [PATCH 2/3] . --- tests/integrations/pydantic_ai/test_pydantic_ai.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index ccff7d6a1f..a9526a0a10 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -2228,7 +2228,6 @@ async def test_invoke_agent_with_instructions( """ from pydantic_ai import Agent - # Create agent with instructions (can be string or list) and system prompt agent = Agent( "test", name="test_instructions", From 74013b5246537325d88c86043e8401cfbbeffde5 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Mon, 31 Aug 2026 15:16:26 -0400 Subject: [PATCH 3/3] lint --- tests/integrations/pydantic_ai/test_pydantic_ai.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index a9526a0a10..03f468e497 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -2268,7 +2268,10 @@ async def test_invoke_agent_with_instructions( ] assert json.loads(system_instructions) == [ {"type": "text", "content": "System prompt"}, - {"type": "text", "content": f"Instruction 1{instructions_separator}Instruction 2"}, + { + "type": "text", + "content": f"Instruction 1{instructions_separator}Instruction 2", + }, ] else: assert SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS not in chat_span["attributes"] @@ -2291,7 +2294,10 @@ async def test_invoke_agent_with_instructions( system_instructions = chat_span["data"][SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS] assert json.loads(system_instructions) == [ {"type": "text", "content": "System prompt"}, - {"type": "text", "content": f"Instruction 1{instructions_separator}Instruction 2"}, + { + "type": "text", + "content": f"Instruction 1{instructions_separator}Instruction 2", + }, ] else: assert SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS not in chat_span["data"]