fix(llmobs): preserve openai assistant content when tool_calls are present#17713
Open
jessicagamio wants to merge 1 commit intoDataDog:mainfrom
Open
fix(llmobs): preserve openai assistant content when tool_calls are present#17713jessicagamio wants to merge 1 commit intoDataDog:mainfrom
jessicagamio wants to merge 1 commit intoDataDog:mainfrom
Conversation
…esent OpenAI's native function-calling schema allows an assistant message to carry both prose `content` and structured `tool_calls` on the same message. The openai LLMObs integration was unconditionally clearing `content` whenever tool_calls were extracted, dropping legitimate assistant narration from replayed history. Only clear `content` when it was the source of the tool_calls (ReAct-style agents), leaving native tool_calls untouched. Also normalize `None` content to `""` before stringifying so that OpenAI responses with `content=None` + `tool_calls` no longer leak the literal string `"None"` into the span (previously masked by the unconditional clear). MLOB-7340 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
contenton any message carryingtool_calls, silently dropping legitimate assistant prose from replayed conversation history.content = ""clear so it only fires whencapture_plain_text_tool_usageactually appended a ReAct-parsed tool call to the list (ReAct content is a stringified duplicate of the structured call; native OpenAI content is independent prose and must be preserved).Nonecontent to""before stringifying — avoids leaking the literal string"None"into the span on OpenAI responses wheretool_callsis set andcontent=None(previously masked by the unconditional clear).Test plan
riot -v run -s -p 3.12 '^openai$' --no-cov -k test_chat_completion_tool_call_preserves_assistant_content or test_chat_completion_react_style_content_still_deduplicates— both new tests pass across all 4 openai riot configs (latest,<2.0.0,~=1.76.2,==1.66.0).riot -v run -s -p 3.12 '^openai$' --no-cov tests/contrib/openai/test_openai_llmobs.py— full file passes (47 passed, 13 skipped) across all 4 openai configs. No regressions totest_chat_completion_tool_call_with_follow_up, which continues to cover thetool_calls-only andtool_results-restructured paths.hatch run lint:style— PASS.hatch run lint:typing—Success: no issues found in 1013 source files.