_convert_json_schema_to_openai_function() — langchain Function Reference
Architecture documentation for the _convert_json_schema_to_openai_function() function in function_calling.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 0edd121c_051a_5776_8748_581f03d9e57c["_convert_json_schema_to_openai_function()"] 344b2838_87a8_d5dc_b550_fdb443ff6c4e["function_calling.py"] 0edd121c_051a_5776_8748_581f03d9e57c -->|defined in| 344b2838_87a8_d5dc_b550_fdb443ff6c4e ea8becf8_0367_1814_460c_decdc8cfa61d["_convert_pydantic_to_openai_function()"] ea8becf8_0367_1814_460c_decdc8cfa61d -->|calls| 0edd121c_051a_5776_8748_581f03d9e57c 4776d470_7c16_396f_5ac7_df8d1e1eeb46["_format_tool_to_openai_function()"] 4776d470_7c16_396f_5ac7_df8d1e1eeb46 -->|calls| 0edd121c_051a_5776_8748_581f03d9e57c ab698410_e291_9809_335f_cba19c23f0a8["_rm_titles()"] 0edd121c_051a_5776_8748_581f03d9e57c -->|calls| ab698410_e291_9809_335f_cba19c23f0a8 style 0edd121c_051a_5776_8748_581f03d9e57c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/function_calling.py lines 122–155
def _convert_json_schema_to_openai_function(
schema: dict,
*,
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:
schema: The JSON schema 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.
Returns:
The function description.
"""
schema = dereference_refs(schema)
if "definitions" in schema: # pydantic 1
schema.pop("definitions", None)
if "$defs" in schema: # pydantic 2
schema.pop("$defs", None)
title = schema.pop("title", "")
default_description = schema.pop("description", "")
return {
"name": name or title,
"description": description or default_description,
"parameters": _rm_titles(schema) if rm_titles else schema,
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does _convert_json_schema_to_openai_function() do?
_convert_json_schema_to_openai_function() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/function_calling.py.
Where is _convert_json_schema_to_openai_function() defined?
_convert_json_schema_to_openai_function() is defined in libs/core/langchain_core/utils/function_calling.py at line 122.
What does _convert_json_schema_to_openai_function() call?
_convert_json_schema_to_openai_function() calls 1 function(s): _rm_titles.
What calls _convert_json_schema_to_openai_function()?
_convert_json_schema_to_openai_function() is called by 2 function(s): _convert_pydantic_to_openai_function, _format_tool_to_openai_function.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free