_convert_pydantic_to_openai_function() — langchain Function Reference
Architecture documentation for the _convert_pydantic_to_openai_function() function in function_calling.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ea8becf8_0367_1814_460c_decdc8cfa61d["_convert_pydantic_to_openai_function()"] 344b2838_87a8_d5dc_b550_fdb443ff6c4e["function_calling.py"] ea8becf8_0367_1814_460c_decdc8cfa61d -->|defined in| 344b2838_87a8_d5dc_b550_fdb443ff6c4e bec7d5d3_e1d0_0526_a4dc_7a24d93ddc26["_convert_python_function_to_openai_function()"] bec7d5d3_e1d0_0526_a4dc_7a24d93ddc26 -->|calls| ea8becf8_0367_1814_460c_decdc8cfa61d afe6c584_4f78_9f27_a452_c0af79a40037["_convert_typed_dict_to_openai_function()"] afe6c584_4f78_9f27_a452_c0af79a40037 -->|calls| ea8becf8_0367_1814_460c_decdc8cfa61d 4776d470_7c16_396f_5ac7_df8d1e1eeb46["_format_tool_to_openai_function()"] 4776d470_7c16_396f_5ac7_df8d1e1eeb46 -->|calls| ea8becf8_0367_1814_460c_decdc8cfa61d 8dd6ec0a_3761_ea6f_0c59_c034b831f0df["convert_to_openai_function()"] 8dd6ec0a_3761_ea6f_0c59_c034b831f0df -->|calls| ea8becf8_0367_1814_460c_decdc8cfa61d 0edd121c_051a_5776_8748_581f03d9e57c["_convert_json_schema_to_openai_function()"] ea8becf8_0367_1814_460c_decdc8cfa61d -->|calls| 0edd121c_051a_5776_8748_581f03d9e57c style ea8becf8_0367_1814_460c_decdc8cfa61d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/function_calling.py lines 158–192
def _convert_pydantic_to_openai_function(
model: type,
*,
name: str | None = None,
description: str | None = None,
rm_titles: bool = True,
) -> FunctionDescription:
"""Converts a Pydantic model to a function description for the OpenAI API.
Args:
model: The Pydantic model to convert.
name: The name of the function.
If not provided, the title of the schema will be used.
description: The description of the function.
If not provided, the description of the schema will be used.
rm_titles: Whether to remove titles from the schema.
Raises:
TypeError: If the model is not a Pydantic model.
Returns:
The function description.
"""
if hasattr(model, "model_json_schema"):
schema = model.model_json_schema() # Pydantic 2
elif hasattr(model, "schema"):
schema = model.schema() # Pydantic 1
else:
msg = "Model must be a Pydantic model."
raise TypeError(msg)
return _convert_json_schema_to_openai_function(
schema, name=name, description=description, rm_titles=rm_titles
)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _convert_pydantic_to_openai_function() do?
_convert_pydantic_to_openai_function() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/function_calling.py.
Where is _convert_pydantic_to_openai_function() defined?
_convert_pydantic_to_openai_function() is defined in libs/core/langchain_core/utils/function_calling.py at line 158.
What does _convert_pydantic_to_openai_function() call?
_convert_pydantic_to_openai_function() calls 1 function(s): _convert_json_schema_to_openai_function.
What calls _convert_pydantic_to_openai_function()?
_convert_pydantic_to_openai_function() is called by 4 function(s): _convert_python_function_to_openai_function, _convert_typed_dict_to_openai_function, _format_tool_to_openai_function, convert_to_openai_function.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free