convert_to_json_schema() — langchain Function Reference
Architecture documentation for the convert_to_json_schema() function in function_calling.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 27d86494_848e_9b3b_d941_5d556a5b249d["convert_to_json_schema()"] 344b2838_87a8_d5dc_b550_fdb443ff6c4e["function_calling.py"] 27d86494_848e_9b3b_d941_5d556a5b249d -->|defined in| 344b2838_87a8_d5dc_b550_fdb443ff6c4e 985b3428_1598_3c9f_dd21_7949746dfdbf["convert_to_openai_tool()"] 27d86494_848e_9b3b_d941_5d556a5b249d -->|calls| 985b3428_1598_3c9f_dd21_7949746dfdbf style 27d86494_848e_9b3b_d941_5d556a5b249d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/function_calling.py lines 560–600
def convert_to_json_schema(
schema: dict[str, Any] | type[BaseModel] | Callable | BaseTool,
*,
strict: bool | None = None,
) -> dict[str, Any]:
"""Convert a schema representation to a JSON schema.
Args:
schema: The schema to convert.
strict: If `True`, model output is guaranteed to exactly match the JSON Schema
provided in the function definition.
If `None`, `strict` argument will not be included in function definition.
Raises:
ValueError: If the input is not a valid OpenAI-format tool.
Returns:
A JSON schema representation of the input schema.
"""
openai_tool = convert_to_openai_tool(schema, strict=strict)
if (
not isinstance(openai_tool, dict)
or "function" not in openai_tool
or "name" not in openai_tool["function"]
):
error_message = "Input must be a valid OpenAI-format tool."
raise ValueError(error_message)
openai_function = openai_tool["function"]
json_schema = {}
json_schema["title"] = openai_function["name"]
if "description" in openai_function:
json_schema["description"] = openai_function["description"]
if "parameters" in openai_function:
parameters = openai_function["parameters"].copy()
json_schema.update(parameters)
return json_schema
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does convert_to_json_schema() do?
convert_to_json_schema() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/function_calling.py.
Where is convert_to_json_schema() defined?
convert_to_json_schema() is defined in libs/core/langchain_core/utils/function_calling.py at line 560.
What does convert_to_json_schema() call?
convert_to_json_schema() calls 1 function(s): convert_to_openai_tool.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free