Update openai.py to handle where OpenAI Agents SDK sends an Omit type#1426
Open
druce wants to merge 2 commits intolangfuse:mainfrom
Open
Update openai.py to handle where OpenAI Agents SDK sends an Omit type#1426druce wants to merge 2 commits intolangfuse:mainfrom
druce wants to merge 2 commits intolangfuse:mainfrom
Conversation
When using OpenAI Agents SDK, an Omit sentinel can be sent, resulting in raising the "metadata must be a dictionary" error
Contributor
|
@druce Thanks a lot for your contribution! Did you check when |
Author
|
line 328 here is where openai sends an Omit object - https://github.com/openai/openai-agents-python/blob/main/src/agents/models/openai_responses.py to replicate: |
Author
|
inadvertently clicked 'close with comment!' |
Author
I think it was here? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using OpenAI Agents SDK, an Omit sentinel can be sent, resulting in raising the "metadata must be a dictionary" error
Important
Adds handling for
Omittype in metadata validation inopenai.pyto prevent TypeError with OpenAI Agents SDK.Omittype in metadata validation in_get_langfuse_data_from_kwargs()inopenai.py.Omitsentinel.Omitfromopenai._types.NotGivenhandling pattern.This description was created by
for 7cc621e. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Updated On: 2025-11-03 18:01:51 UTC
Greptile Summary
Adds handling for OpenAI's
Omitsentinel type in metadata validation to prevent TypeError when using the OpenAI Agents SDK.Key changes:
Omittype fromopenai._typesalongside existingNotGivenimportisinstance(metadata, Omit)check in_get_langfuse_data_from_kwargsfunction at langfuse/openai.py:401Context:
This mirrors a previous fix (commit 9c6a71d) that added
NotGivenhandling. The OpenAI Agents SDK can sendOmitsentinel values for optional parameters, which was causing the "metadata must be a dictionary" validation error to be raised incorrectly. The fix follows the established pattern and allowsOmitvalues to pass through validation just likeNotGivenvalues.Confidence Score: 4/5
Omittype handling to match the existingNotGivenpattern. It directly addresses the reported issue without introducing new logic. Score of 4 (not 5) due to lack of test coverage for the newOmithandling, though the change follows the established pattern.Important Files Changed
File Analysis
Omittype handling to metadata validation, mirroring existingNotGivencheck to prevent TypeError when OpenAI Agents SDK passes Omit sentinelSequence Diagram
sequenceDiagram participant AgentsSDK as OpenAI Agents SDK participant LangfuseOpenAI as langfuse.openai participant Validator as _get_langfuse_data_from_kwargs participant Client as Langfuse Client AgentsSDK->>LangfuseOpenAI: API call with metadata=Omit LangfuseOpenAI->>Validator: Extract kwargs Validator->>Validator: Check metadata type alt metadata is Omit Validator->>Validator: Skip validation (Omit sentinel) else metadata is NotGiven Validator->>Validator: Skip validation (NotGiven sentinel) else metadata is dict Validator->>Validator: Validation passes else metadata is other type Validator-->>LangfuseOpenAI: Raise TypeError end Validator->>Client: Pass validated metadata Client->>Client: Process trace/observation