Skip to content

Conversation

@zhongyu09
Copy link

@zhongyu09 zhongyu09 commented Sep 5, 2025

Fix #113

Summary

  • Add strict_mode parameter to create_manage_memory_tool and create_search_memory_tool
  • Implement _ToolStrictCompatible class that ensures OpenAI structured outputs strict mode compatibility by force to set required to include all properties and set additionalProperties to false where it was previously true

Problem

OpenAI's structured outputs strict mode requires all properties to be in the required array, but the current implementation has required: [], causing a 400 error:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for function 'manage_memory': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'content'.", 'type': 'invalid_request_error', 'param': 'tools[4].function.parameters', 'code': 'invalid_function_parameters'}}

Solution

  • Added strict_mode: bool = False parameter to both tool creation functions
  • Created _ToolStrictCompatible class that modifies the JSON schema to:
    • Set required to include all properties: schema["required"] = list(props.keys())
    • Set additionalProperties to false where it was previously true
  • Maintains backward compatibility by defaulting to strict_mode=False

Usage

# For OpenAI strict mode compatibility
manage_memory_tool = create_manage_memory_tool(
    namespace=("memories", "{user_id}"),
    strict_mode=True  # <-- Add this for OpenAI strict mode
)

search_tool = create_search_memory_tool(
    namespace=("memories", "{user_id}"),
    strict_mode=True  # <-- Add this for OpenAI strict mode
)

# Use with OpenAI
llm_with_tools = llm.bind_tools([manage_memory_tool], strict=True)

@zhongyu09
Copy link
Author

Hi @hinthornw, can you have a look for this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool failed in OpenAI structured-outputs strict mode

1 participant