fix(openai): treat openai Omit sentinels like NotGiven when logging - #1805
Merged
Conversation
DavidTraina
force-pushed
the
fix/openai-omit-sentinels
branch
from
August 10, 2026 22:33
4c14706 to
fa50c2f
Compare
DavidTraina
marked this pull request as ready for review
August 10, 2026 22:45
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.
What does this PR do?
Addresses langfuse/langfuse#10057
openai v2 ships the
Omitsentinel alongsideNotGivenfor unset params, and callers commonly forward it: the openai-agents SDK (>= 0.4.0) passesOmitfor unset params such astemperature,top_p,tool_choice,parallel_tool_calls, andinstructions(see_non_null_or_omitinagents/models/openai_responses.py), and langchain-openai does too (the linked issue reproduces with langchain-openai + openai 2.6.1, no agents SDK involved). Theisinstance(metadata, NotGiven)TypeError crash in the linked issue's traceback is already guarded on current main; what remains is that the OpenAI instrumentation only filteredNotGiven, soOmitsentinels leaked into logged generations as junk like"<openai.Omit object at 0x...>"(str-repr paths) or{}(EventSerializer output):_extract_responses_prompt: anOmitinstructionsfabricated a system message whose content was theOmitrepr;Omittool_choice/parallel_tool_calls/tools/inputleaked into the logged input._get_langfuse_data_from_kwargs:Omittemperature,top_p, etc. were logged as sentinel objects instead of falling back to defaults._serialize_openai_value/ metadata handling:Omitserialized to itsstr()repr._extract_chat_prompt(Chat Completions path):functions/function_call/toolswere only checked againstNone, so bothNotGivenandOmitsentinels leaked into the logged input.This PR treats
Omitexactly likeNotGivenon all logging paths:_is_not_givennow checks against(NotGiven, Omit), all directisinstance(..., NotGiven)checks route through_is_not_given, and_extract_chat_promptfilters sentinels too.Relation to #1426: that PR only patches the metadata validation path in
_get_langfuse_data_from_kwargs(which no longer raises on current main). This PR is a superset — it covers that metadata case plus the prompt/input fields, model parameters, and the chat-completions path, with unit tests.Type of change
Verification
List the main commands you ran:
Note:
uv run --frozen ruff format --check .flagstests/unit/test_media.py, but that drift pre-exists onmainand is untouched here. e2e / live_provider suites were not run (unit-testable instrumentation change).Checklist
code_review.md..env.templateif needed.🤖 Generated with Claude Code
Greptile Summary
This PR updates the OpenAI integration’s prompt, metadata, model-parameter, serialization, and raw-response extraction paths to treat
Omitas an unset sentinel alongsideNotGiven._is_not_given.Confidence Score: 4/5
This PR should not merge until the
Omitimport is made compatible with supported older OpenAI SDK versions.The sentinel filtering itself is consistently implemented and tested, but importing the integration now fails before its existing version-specific compatibility paths can run when
Omitis unavailable.Files Needing Attention: langfuse/openai.py
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(openai): treat openai Omit sentinels..." | Re-trigger Greptile
Context used: