Skip to content

[Bug]: Undefined array key "key" (and "value") in FileSearchComparisonFilter.php #663

@adatta02

Description

@adatta02

Description

On the OpenAI API, the File Search Tool / Searching a vector store supports nesting multiple CompoundFilters in the "filters" parameter to create a complex expression.

The library supports creating API requests of that type but when OpenAI returns the data the library errors while trying to parse the "filters" object returned via the API.

The errors you get are:

[Wed Aug 27 15:15:37 2025] PHP Warning:  Undefined array key "key" in /home/ashish/workspace/college-access-poc/vendor/openai-php/client/src/Responses/Responses/Tool/FileSearchComparisonFilter.php on line 40
[Wed Aug 27 15:15:37 2025] PHP Warning:  Undefined array key "value" in /home/ashish/workspace/college-access-poc/vendor/openai-php/client/src/Responses/Responses/Tool/FileSearchComparisonFilter.php on line 42

When the API response "tools" key looks like this:

    "tools": [
        {
            "type": "file_search",
            "filters": {
                "type": "and",
                "filters": [
                    {
                        "type": "and",
                        "filters": [
                            {
                                "type": "ne",
                                "key": "state",
                                "value": "ny"
                            },
                            {
                                "type": "ne",
                                "key": "state",
                                "value": "ca"
                            }
                        ]
                    }
                ]
            },
            "max_num_results": 5,
            "ranking_options": {
                "ranker": "auto",
                "score_threshold": 0.1
            },
            "vector_store_ids": [
                "vs_68a38ae83c288191a1071eeb288e8fb5",
                "vs_68adf7d2880481919bde619efeb1526f"
            ]
        }
    ],

https://platform.openai.com/docs/api-reference/vector_stores/search

Steps To Reproduce

  1. Create an OpenAI vector store and add some documents
  2. Use the Responses API with a file search tool and a nested filter object like this:
$result = $client->responses()->create([
    'model' => 'gpt-4.1-2025-04-14',
    'input' => $data["search"],
    'instructions' => $data["prompt"],
    'include' => ['file_search_call.results'],
    'temperature' => 0,
    'tools' => [
        [
            'type' => 'file_search',
            'vector_store_ids' => [$data["vector_id"]],
            'filters' => [
                "type" => "or",
                "filters" => [[
                    "type" => "or",
                    "filters" => [
                        [ "type" => "eq", "key" => "state", "value" => "ny" ],
                        [ "type" => "ne", "key" => "state", "value" => "ca" ],
                    ],
                ]],
            ]
        ]
    ]
]);

OpenAI PHP Client Version

v0.16.0

PHP Version

8.3.24

Notes

The issue is in how FileSearchTool and FileSearchCompoundFilter parse the filters that come back from OpenAI in this case.

It looked like some refactoring would need to be done to allow a list of FileSearchCompoundFilter in FileSearchTool as well as allowing FileSearchCompoundFilter to hold FileSearchCompoundFilter children itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions