Utilities
utils
¶
Utility functions for LangChain.
These functions do not depend on any other LangChain module.
function_calling
¶
Methods for creating function specs in the style of OpenAI Functions.
| FUNCTION | DESCRIPTION |
|---|---|
convert_to_json_schema |
Convert a schema representation to a JSON schema. |
convert_to_openai_tool |
Convert a tool-like object to an OpenAI tool schema. |
convert_to_json_schema
¶
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.
| PARAMETER | DESCRIPTION |
|---|---|
schema
|
The schema to convert.
TYPE:
|
strict
|
If
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the input is not a valid OpenAI-format tool. |
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
A JSON schema representation of the input schema. |
convert_to_openai_tool
¶
convert_to_openai_tool(
tool: dict[str, Any] | type[BaseModel] | Callable | BaseTool,
*,
strict: bool | None = None,
) -> dict[str, Any]
Convert a tool-like object to an OpenAI tool schema.
| PARAMETER | DESCRIPTION |
|---|---|
tool
|
Either a dictionary, a
TYPE:
|
strict
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
A dict version of the passed in tool which is compatible with the |
dict[str, Any]
|
OpenAI tool-calling API. |
Behavior changed in langchain-core 0.3.16
description and parameters keys are now optional. Only name is
required and guaranteed to be part of the output.
Behavior changed in langchain-core 0.3.44
Return OpenAI Responses API-style tools unchanged. This includes
any dict with "type" in "file_search", "function",
"computer_use_preview", "web_search_preview".
Behavior changed in langchain-core 0.3.63
Added support for OpenAI's image generation built-in tool.