Skip to content

OpenAI API tool_use fails when using array parameters – items not included in JSON Schema #16

@KatHaruto

Description

@KatHaruto

When using the tool_use in openai api feature with a tool that has an array-type parameter, an error occurs during execution.

it seems that during the conversion from OpenAPI to JSON Schema, the items object associated with the array parameter is missing in the resulting schema. This causes the validation or tool execution to fail.

example

OpenAPI Schema

...

"/pet/findByTags": {
      "get": {
        "tags": ["pet"],
        "summary": "Finds Pets by tags.",
        "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
        "operationId": "findPetsByTags",
        "parameters": [
          {
            "name": "tags",
            "in": "query",
            "description": "Tags to filter by",
            "required": true,
            "explode": true,
            "schema": { "type": "array", "items": { "type": "string" } }
          }
        ],

...

Generated mcp input schema (low-level mode)

{
    "type": "object",
    "properties": {
        "tags": {
            "type": "array", 
            "description": "Tags to filter by"
        }
    }, 
    "required": [], 
    "additionalProperties": false
}

openai api cause error using mcp tools

openai.BadRequestError: Error code: 400 - 
{
    'error': {
        'message': "Invalid schema for function 'get_pet_findByTags': In context=('properties', 'tags'), array schema missing items.",
        'type': 'invalid_request_error',
        'param': 'tools[0].parameters',
        'code': 'invalid_function_parameters',
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions