langchain_core.utils.function_calling.convert_to_openai_tool¶

langchain_core.utils.function_calling.convert_to_openai_tool(tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool], *, strict: Optional[bool] = None) Dict[str, Any][source]¶

Convert a raw function/class to an OpenAI tool.

Changed in version 0.2.29: strict arg added.

Parameters
  • tool (Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool]) – Either a dictionary, a pydantic.BaseModel class, Python function, or BaseTool. If a dictionary is passed in, it is assumed to already be a valid OpenAI tool, OpenAI function, or a JSON schema with top-level ‘title’ and ‘description’ keys specified.

  • strict (Optional[bool]) –

    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 tool definition.

    New in version 0.2.29.

Returns

A dict version of the passed in tool which is compatible with the OpenAI tool-calling API.

Return type

Dict[str, Any]