mirror of
https://github.com/hwchase17/langchain.git
synced 2026-07-11 01:01:41 +00:00
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".
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user