diff --git a/libs/langchain/langchain/tools/convert_to_openai.py b/libs/langchain/langchain/tools/convert_to_openai.py index 82c0a47fbbd..e575b024d4b 100644 --- a/libs/langchain/langchain/tools/convert_to_openai.py +++ b/libs/langchain/langchain/tools/convert_to_openai.py @@ -19,7 +19,9 @@ def format_tool_to_openai_function(tool: BaseTool) -> FunctionDescription: if isinstance(tool, StructuredTool): schema_ = tool.args_schema.schema() # Bug with required missing for structured tools. - required = sorted(schema_["properties"]) # BUG WORKAROUND + required = schema_.get( + "required", sorted(schema_["properties"]) # Backup is a BUG WORKAROUND + ) return { "name": tool.name, "description": tool.description,