Skip to content

Conversation

@druce
Copy link

@druce druce commented Nov 3, 2025

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 Omit type in metadata validation in openai.py to prevent TypeError with OpenAI Agents SDK.

  • Behavior:
    • Adds handling for Omit type in metadata validation in _get_langfuse_data_from_kwargs() in openai.py.
    • Prevents TypeError when OpenAI Agents SDK sends Omit sentinel.
  • Imports:
    • Imports Omit from openai._types.
  • Misc:
    • Mirrors existing NotGiven handling pattern.

This description was created by Ellipsis 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 Omit sentinel type in metadata validation to prevent TypeError when using the OpenAI Agents SDK.

Key changes:

  • Imports Omit type from openai._types alongside existing NotGiven import
  • Adds isinstance(metadata, Omit) check in _get_langfuse_data_from_kwargs function at langfuse/openai.py:401

Context:
This mirrors a previous fix (commit 9c6a71d) that added NotGiven handling. The OpenAI Agents SDK can send Omit sentinel 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 allows Omit values to pass through validation just like NotGiven values.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The change is a straightforward fix that adds Omit type handling to match the existing NotGiven pattern. It directly addresses the reported issue without introducing new logic. Score of 4 (not 5) due to lack of test coverage for the new Omit handling, though the change follows the established pattern.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
langfuse/openai.py 4/5 Added Omit type handling to metadata validation, mirroring existing NotGiven check to prevent TypeError when OpenAI Agents SDK passes Omit sentinel

Sequence 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
Loading

When using OpenAI Agents SDK, an Omit sentinel can be sent, resulting in raising the "metadata must be a dictionary" error
@CLAassistant
Copy link

CLAassistant commented Nov 3, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@hassiebp hassiebp self-requested a review November 3, 2025 17:44
@hassiebp
Copy link
Contributor

hassiebp commented Nov 3, 2025

@druce Thanks a lot for your contribution! Did you check when Omit was added to the OpenAI SDK so we can avoid missing import errors on usage with older OpenAI SDK versions?

@druce
Copy link
Author

druce commented Nov 3, 2025

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:
in environment set OPENAI_API_KEY, LANGFUSE_TRACING_ENABLED=true, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_HOST
run test.py:

import asyncio
from agents import Agent, Runner, set_default_openai_client
from langfuse.openai import AsyncOpenAI  # Use Langfuse-wrapped client


class SimpleAgent(Agent):
    def __init__(self):
        super().__init__(name="Test", model="gpt-4o-mini", instructions="You are helpful")


async def main():
    # This client is wrapped by Langfuse
    set_default_openai_client(AsyncOpenAI())
    result = await Runner.run(SimpleAgent(), "Hello")
    print("Success:", result.final_output)


if __name__ == "__main__":
    asyncio.run(main())

@druce druce closed this Nov 3, 2025
@druce druce reopened this Nov 3, 2025
@druce
Copy link
Author

druce commented Nov 3, 2025

inadvertently clicked 'close with comment!'

@druce
Copy link
Author

druce commented Nov 3, 2025

@druce Thanks a lot for your contribution! Did you check when Omit was added to the OpenAI SDK so we can avoid missing import errors on usage with older OpenAI SDK versions?

I think it was here?

openai/openai-agents-python@9407743

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

3 participants