Test to verify structured output is generated both on invoke and stream.
This test is optional and should be skipped if the model does not support structured output (see configuration below).
To disable structured output tests, set has_structured_output to False
in your test class:
class TestMyChatModelIntegration(ChatModelIntegrationTests):
@property
def has_structured_output(self) -> bool:
return False
By default, has_structured_output is True if a model overrides the
with_structured_output or bind_tools methods.
If this test fails, ensure that the model's bind_tools method
properly handles both JSON Schema and Pydantic V2 models.
langchain_core implements a utility function.
that will accommodate most formats.
See example implementation.
of with_structured_output.
test_structured_output_async(
self,
model: BaseChatModel,
schema_type: Literal['pydantic', 'typeddict', 'json_schema']
) -> None