Skip to content

The agent engineering platform.

docs(core): improve style for refs (#34227)

Mason Daugherty80c397019f0b
diff --git a/libs/core/langchain_core/language_models/chat_models.py b/libs/core/langchain_core/language_models/chat_models.py
index a21aba27c8..911556722f 100644
--- a/libs/core/langchain_core/language_models/chat_models.py
+++ b/libs/core/langchain_core/language_models/chat_models.py
@@ -1578,86 +1578,86 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
depends on the `schema` as described above.
- `'parsing_error'`: `BaseException | None`
- Example: Pydantic schema (`include_raw=False`):
+ ???+ example "Pydantic schema (`include_raw=False`)"
- ```python
- from pydantic import BaseModel
+ ```python
+ from pydantic import BaseModel
- class AnswerWithJustification(BaseModel):
- '''An answer to the user question along with justification for the answer.'''
+ class AnswerWithJustification(BaseModel):
+ '''An answer to the user question along with justification for the answer.'''
- answer: str
- justification: str
+ answer: str
+ justification: str
- model = ChatModel(model="model-name", temperature=0)
- structured_model = model.with_structured_output(AnswerWithJustification)
+ model = ChatModel(model="model-name", temperature=0)
+ structured_model = model.with_structured_output(AnswerWithJustification)
- structured_model.invoke(
- "What weighs more a pound of bricks or a pound of feathers"
- )
+ structured_model.invoke(
+ "What weighs more a pound of bricks or a pound of feathers"
+ )
- # -> AnswerWithJustification(
- # answer='They weigh the same',
- # justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
- # )
- ```
+ # -> AnswerWithJustification(
+ # answer='They weigh the same',
+ # justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'
+ # )
+ ```
- Example: Pydantic schema (`include_raw=True`):
+ ??? example "Pydantic schema (`include_raw=True`)"
- ```python
- from pydantic import BaseModel
+ ```python
+ from pydantic import BaseModel
- class AnswerWithJustification(BaseModel):
- '''An answer to the user question along with justification for the answer.'''
+ class AnswerWithJustification(BaseModel):
+ '''An answer to the user question along with justification for the answer.'''
- answer: str
- justification: str
+ answer: str
+ justification: str
- model = ChatModel(model="model-name", temperature=0)
- structured_model = model.with_structured_output(
- AnswerWithJustification, include_raw=True
- )
+ model = ChatModel(model="model-name", temperature=0)
+ structured_model = model.with_structured_output(
+ AnswerWithJustification, include_raw=True
+ )
- structured_model.invoke(
- "What weighs more a pound of bricks or a pound of feathers"
- )
- # -> {
- # 'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
- # 'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
- # 'parsing_error': None
- # }
- ```
+ structured_model.invoke(
+ "What weighs more a pound of bricks or a pound of feathers"
+ )
+ # -> {
+ # 'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_Ao02pnFYXD6GN1yzc0uXPsvF', 'function': {'arguments': '{"answer":"They weigh the same.","justification":"Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ."}', 'name': 'AnswerWithJustification'}, 'type': 'function'}]}),
+ # 'parsed': AnswerWithJustification(answer='They weigh the same.', justification='Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume or density of the objects may differ.'),
+ # 'parsing_error': None
+ # }
+ ```
- Example: Dictionary schema (`include_raw=False`):
+ ??? example "Dictionary schema (`include_raw=False`)"
- ```python
- from pydantic import BaseModel
- from langchain_core.utils.function_calling import convert_to_openai_tool
+ ```python
+ from pydantic import BaseModel
+ from langchain_core.utils.function_calling import convert_to_openai_tool
- class AnswerWithJustification(BaseModel):
- '''An answer to the user question along with justification for the answer.'''
+ class AnswerWithJustification(BaseModel):
+ '''An answer to the user question along with justification for the answer.'''
- answer: str
- justification: str
+ answer: str
+ justification: str
- dict_schema = convert_to_openai_tool(AnswerWithJustification)
- model = ChatModel(model="model-name", temperature=0)
- structured_model = model.with_structured_output(dict_schema)
+ dict_schema = convert_to_openai_tool(AnswerWithJustification)
+ model = ChatModel(model="model-name", temperature=0)
+ structured_model = model.with_structured_output(dict_schema)
- structured_model.invoke(
- "What weighs more a pound of bricks or a pound of feathers"
- )
- # -> {
- # 'answer': 'They weigh the same',
- # 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
- # }
- ```
+ structured_model.invoke(
+ "What weighs more a pound of bricks or a pound of feathers"
+ )
+ # -> {
+ # 'answer': 'They weigh the same',
+ # 'justification': 'Both a pound of bricks and a pound of feathers weigh one pound. The weight is the same, but the volume and density of the two substances differ.'
+ # }
+ ```
!!! warning "Behavior changed in `langchain-core` 0.2.26"