Skip to content

The agent engineering platform.

docs(standard-tests): improve doc for `structured_output_kwargs` and `supports_json_mode` (#34178)

Mason Daugherty064b37f90e8c
diff --git a/libs/standard-tests/langchain_tests/integration_tests/chat_models.py b/libs/standard-tests/langchain_tests/integration_tests/chat_models.py
index b908a0ccf6..a9c5ff9fc2 100644
--- a/libs/standard-tests/langchain_tests/integration_tests/chat_models.py
+++ b/libs/standard-tests/langchain_tests/integration_tests/chat_models.py
@@ -291,24 +291,45 @@ class ChatModelIntegrationTests(ChatModelTests):
??? info "`structured_output_kwargs`"
- Dict property that can be used to specify additional kwargs for
- `with_structured_output`.
+ Dict property specifying additional kwargs to pass to
+ `with_structured_output()` when running structured output tests.
- Useful for testing different models.
+ Override this to customize how your model generates structured output.
+
+ The most common use case is specifying the `method` parameter:
+
+ - `'function_calling'`: Uses tool/function calling to enforce the schema.
+ - `'json_mode'`: Uses the model's JSON mode.
+ - `'json_schema'`: Uses native JSON schema support (e.g., OpenAI's structured
+ outputs).
```python
@property
def structured_output_kwargs(self) -> dict:
- return {"method": "function_calling"}
+ return {"method": "json_schema"}
```
??? info "`supports_json_mode`"
- Boolean property indicating whether the chat model supports JSON mode in
- `with_structured_output`.
+ Boolean property indicating whether the chat model supports
+ `method='json_mode'` in `with_structured_output`.
+
+ JSON mode constrains the model to output valid JSON without enforcing
+ a specific schema (unlike `'function_calling'` or `'json_schema'` methods).
+
+ When using JSON mode, you must prompt the model to output JSON in your
+ message.
+
+ Example:
+ ```python
+ structured_llm = llm.with_structured_output(MySchema, method="json_mode")
+ structured_llm.invoke("... Return the result as JSON.")
+ ```
See docs for [Structured output](https://docs.langchain.com/oss/python/langchain/structured-output).
+ Defaults to `False`.
+
```python
@property
def supports_json_mode(self) -> bool:
diff --git a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py
index e82c3ac54a..f23639f49c 100644
--- a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py
+++ b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py
@@ -118,7 +118,27 @@ class ChatModelTests(BaseStandardTests):
@property
def structured_output_kwargs(self) -> dict:
- """If specified, additional kwargs for `with_structured_output`."""
+ """Additional kwargs to pass to `with_structured_output()` in tests.
+
+ Override this property to customize how structured output is generated
+ for your model. The most common use case is specifying the `method`
+ parameter, which controls the mechanism used to enforce structured output:
+
+ - `'function_calling'`: Uses tool/function calling to enforce the schema.
+ - `'json_mode'`: Uses the model's JSON mode.
+ - `'json_schema'`: Uses native JSON schema support (e.g., OpenAI's
+ structured outputs).
+
+ Returns:
+ A dict of kwargs passed to `with_structured_output()`.
+
+ Example:
+ ```python
+ @property
+ def structured_output_kwargs(self) -> dict:
+ return {"method": "json_schema"}
+ ```
+ """
return {}
@property
@@ -356,24 +376,45 @@ class ChatModelUnitTests(ChatModelTests):
??? info "`structured_output_kwargs`"
- Dict property that can be used to specify additional kwargs for
- `with_structured_output`.
+ Dict property specifying additional kwargs to pass to
+ `with_structured_output()` when running structured output tests.
+
+ Override this to customize how your model generates structured output.
- Useful for testing different models.
+ The most common use case is specifying the `method` parameter:
+
+ - `'function_calling'`: Uses tool/function calling to enforce the schema.
+ - `'json_mode'`: Uses the model's JSON mode.
+ - `'json_schema'`: Uses native JSON schema support (e.g., OpenAI's structured
+ outputs).
```python
@property
def structured_output_kwargs(self) -> dict:
- return {"method": "function_calling"}
+ return {"method": "json_schema"}
```
??? info "`supports_json_mode`"
- Boolean property indicating whether the chat model supports JSON mode in
- `with_structured_output`.
+ Boolean property indicating whether the chat model supports
+ `method='json_mode'` in `with_structured_output`.
+
+ JSON mode constrains the model to output valid JSON without enforcing
+ a specific schema (unlike `'function_calling'` or `'json_schema'` methods).
+
+ When using JSON mode, you must prompt the model to output JSON in your
+ message.
+
+ Example:
+ ```python
+ structured_llm = llm.with_structured_output(MySchema, method="json_mode")
+ structured_llm.invoke("... Return the result as JSON.")
+ ```
See docs for [Structured output](https://docs.langchain.com/oss/python/langchain/structured-output).
+ Defaults to `False`.
+
```python
@property
def supports_json_mode(self) -> bool: