Skip to content

Unchecked access to optional keys in $attributes in public static function from() in multiple classes. #781

@abelmannconsulting

Description

@abelmannconsulting

I am using the library not only to talk to open ai, but also to talk to azure ai agents that fully support the responses api. It looks like azure ai skips empty attributes in their response and openai does not. This causes problems in some classes where the code tries to access the array index of optional attribute without checking if it exists:

  1. Example - WebSearchUserLocation.php:

The constructor shows that "city" is optional:

public readonly ?string $city

But in public static function from() the acces to it is not checked:

city: $attributes['city'],

Much better would be this:

city: $attributes['city'] ?? null,

  1. Example - OutputMcpCall.php:

The construtor shows that "approvalRequestId" is optional:

public readonly ?string $approvalRequestId = null,

But the same in public static function from():

approvalRequestId: $attributes['approval_request_id'],

While this would be much better:

approvalRequestId: $attributes['approval_request_id'] ?? null,

I am not sure if you are generating this could automatically. If not I could start making pull request for all those cases where I run into a problem. Should I do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions