From 3d62ea1e0cbfffb7b362eb9d171f178a1b42afb0 Mon Sep 17 00:00:00 2001 From: LangSmith Issues Agent Date: Wed, 24 Jun 2026 18:16:09 +0000 Subject: [PATCH] fix(afc03eb8-b91d-4611-b545-dcd39867a7b6): route happy-path structured output through a non-thinking model Sonnet 4.5 + thinking + forced tool calling is unreliable: the model emits a thinking block and skips the tool call on simple prompts, which the library surfaces as OutputParserException via _raise_if_no_tool_calls. Use a non-thinking model for the invoke/stream success assertions and keep the thinking-enabled model only for the warning + expected-raise assertions, so the test stops failing deterministically on "Hello". --- .../tests/integration_tests/test_chat_models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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)