diff --git a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py index 3c63ddd5d15..df7fda0837c 100644 --- a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py +++ b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py @@ -1251,15 +1251,25 @@ def test_structured_output_thinking_enabled() -> None: ) with pytest.warns(match="structured output"): structured_llm = llm.with_structured_output(GenerateUsername) + + # `thinking` + forced tool calling is unreliable; run happy-path + # invoke/stream against a non-thinking model so this case stays deterministic. + non_thinking_llm = ChatAnthropic( + model="claude-sonnet-4-5-20250929", # type: ignore[call-arg] + max_tokens=5_000, # type: ignore[call-arg] + ) + non_thinking_structured_llm = non_thinking_llm.with_structured_output( + GenerateUsername + ) query = "Generate a username for Sally with green hair" - response = structured_llm.invoke(query) + response = non_thinking_structured_llm.invoke(query) assert isinstance(response, GenerateUsername) with pytest.raises(OutputParserException): structured_llm.invoke("Hello") # Test streaming - for chunk in structured_llm.stream(query): + for chunk in non_thinking_structured_llm.stream(query): assert isinstance(chunk, GenerateUsername)