Home / Function/ test_with_structured_output() — langchain Function Reference

test_with_structured_output() — langchain Function Reference

Architecture documentation for the test_with_structured_output() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  51884335_c547_0761_35f3_3a33de8633a3["test_with_structured_output()"]
  f4b40f56_1158_0e72_1cac_d0121e4eabd8["ChatModelUnitTests"]
  51884335_c547_0761_35f3_3a33de8633a3 -->|defined in| f4b40f56_1158_0e72_1cac_d0121e4eabd8
  style 51884335_c547_0761_35f3_3a33de8633a3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/unit_tests/chat_models.py lines 1037–1067

    def test_with_structured_output(
        self,
        model: BaseChatModel,
        schema: Any,
    ) -> None:
        """Test `with_structured_output` method.

        Test is skipped if the `has_structured_output` property on the test class is
        False.

        ??? question "Troubleshooting"

            If this test fails, ensure that the model's `bind_tools` method
            properly handles Pydantic V2 models.

            `langchain_core` implements a [utility function](https://reference.langchain.com/python/langchain_core/utils/?h=convert_to_op#langchain_core.utils.function_calling.convert_to_openai_tool).
            that will accommodate most formats.

            See [example implementation](https://github.com/langchain-ai/langchain/blob/master/libs/partners/openai/langchain_openai/chat_models/base.py).
            of `with_structured_output`.
        """
        if not self.has_structured_output:
            return

        assert model.with_structured_output(schema) is not None
        for method in ["json_schema", "function_calling", "json_mode"]:
            strict_values = [None, False, True] if method != "json_mode" else [None]
            for strict in strict_values:
                assert model.with_structured_output(
                    schema, method=method, strict=strict
                )

Domain

Subdomains

Frequently Asked Questions

What does test_with_structured_output() do?
test_with_structured_output() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/unit_tests/chat_models.py.
Where is test_with_structured_output() defined?
test_with_structured_output() is defined in libs/standard-tests/langchain_tests/unit_tests/chat_models.py at line 1037.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free