Repository navigation
fix(instrumentation): redact tool call arguments with the text hiding flags - #4048
RichardoMrMu wants to merge 5 commits into
Conversation
… flags hide_input_text / hide_output_text redact message content and message_content.text, but never matched the tool call arguments leaf, so llm.<input|output>_messages.<i>.message.tool_calls.<j>.tool_call.function.arguments and the legacy message.function_call_arguments_json spelling were exported in full even with the text hiding flags enabled. Extend both flags to the arguments leaf; the tool call id and function name stay visible. Assisted-by: Doubao
|
@mikeldking @sanchitram1 could you approve the fork workflows on this PR? Nothing has run on this branch yet. |
# Conflicts: # python/openinference-instrumentation/tests/test_config.py
|
The factory started a review of 19b6400 (session |
There was a problem hiding this comment.
Factory review of 19b6400: Request changes
Checks fail: the new redaction breaks one openai test and one vertexai test that pass on main.
| Criterion | Result | Notes |
|---|---|---|
| Fit | Pass | does what it claims |
| Checks | Fail | ci-openai, ci-vertexai |
| Tests | Pass | all 6 new redaction cases fail without the change |
| Blocking findings | 1 | breaks existing hiding tests config.py:429 |
| Non-blocking findings | 1 | spec/docs not updated, JS/Go diverge config.py:597 |
| Risk | Low | backwards compatibility: opt-in flags now hide tool arguments |
| Review depth | Deep | touches the openinference-instrumentation core |
Details
Intent: Make TraceConfig.hide_input_text / hide_output_text also redact tool call arguments in input/output messages (...tool_calls.<j>.tool_call.function.arguments and legacy ...message.function_call_arguments_json), leaving the call id and function name visible.
Fit: The two new elif branches and _is_tool_call_arguments do exactly that.
The new branches come after hide_inputs/hide_input_messages, so dropping messages still wins.
They don't touch input.value, llm.tools.* or TOOL-span tool_call.*.
The gen_ai.* dual-write is built from the masked attributes, so redacted arguments carry through to it.
The diff changes nothing the PR doesn't claim.
Verified:
tox run -e ci-instrumentationpasses: ruff format, ruff check, mypy, 8599 tests.- With the base
config.pyinstalled, the 6 new redaction cases fail (4test_trace_configcases and bothtest_text_hiding_covers_helper_emitted_tool_call_argumentscases); with the PR they pass. ci-openaifailstest_chat_completions_with_config_hiding_hiding_outputs[True-False-False], andci-vertexaifailstest_instrumentor_config_hiding_outputs[True-False-False]. Both pass with the baseconfig.pyin the same envs.ci-anthropic,ci-groq,ci-strands_agents,ci-instructor,ci-langchain,ci-llama_indexandci-openai_agentspass.
Not verified:- The other instrumentor tox envs, which CI runs because the core changed. I ran every instrumentor whose tests reference the text-hiding flags, plus openai and vertexai.
- The
-latestvariants and py3.10/py3.14: the sandbox only has Python 3.11.
Findings without a diff line: none
Risk: side effects low, performance none, backwards compatibility low: users who already sethide_*_textwill now see__REDACTED__for tool arguments in spans andgen_ai.*. Ratings from the Python reviewer.
Graded against the review criteria.
| elif ( | ||
| self.hide_input_text | ||
| and SpanAttributes.LLM_INPUT_MESSAGES in key | ||
| and _is_tool_call_arguments(key) | ||
| ): | ||
| value = REDACTED_VALUE | ||
| elif ( | ||
| self.hide_output_text | ||
| and SpanAttributes.LLM_OUTPUT_MESSAGES in key | ||
| and _is_tool_call_arguments(key) | ||
| ): | ||
| value = REDACTED_VALUE |
There was a problem hiding this comment.
Blocking. These new branches break two instrumentor tests that pass on main. CI runs every instrumentor when the core changes, so CI will fail here.
tox run -e ci-openai:test_instrumentor.py::test_chat_completions_with_config_hiding_hiding_outputs[True-False-False](hide_output_text=True) fails attest_instrumentor.py:1599. It expects the rawmessage.function_call_arguments_jsonand getsAssertionError: assert '__REDACTED__' == '0.4360070478690712'.tox run -e ci-vertexai:test_gapic_client.py::test_instrumentor_config_hiding_outputs[True-False-False]fails attest_gapic_client.py:511.json.loads(args_json_str)raisesJSONDecodeErrorbecausetool_call.function.argumentsis now__REDACTED__.
I swapped the base config.py into the same tox envs and both suites pass (564 and 150 passed). With this PR's config.py, exactly these two tests fail.
Fix: in both tests, expect REDACTED_VALUE for the arguments leaf when hide_output_text (hide_text in the openai helper) is set. I also ran anthropic, groq, strands_agents, instructor, langchain, llama_index and openai_agents, and they pass. The other instrumentors are unverified, so run the full matrix before pushing.
| def _is_tool_call_arguments(key: str) -> bool: | ||
| """True for the arguments payload of a tool call, in either the nested | ||
| (``llm.input_messages.0.message.tool_calls.0.tool_call.function.arguments``) | ||
| or the legacy (``llm.input_messages.0.message.function_call_arguments_json``) | ||
| spelling. The arguments JSON is message text, so the text-hiding flags cover | ||
| it; the call's id and function name stay visible as structure.""" | ||
| return key.endswith(ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON) or key.endswith( | ||
| MessageAttributes.MESSAGE_FUNCTION_CALL_ARGUMENTS_JSON | ||
| ) |
There was a problem hiding this comment.
Non-blocking. This widens what hide_input_text / hide_output_text cover, but the documented contract is unchanged and the other languages don't follow.
- Spec and docs still describe the old behavior:
spec/configuration.md:18,20andspec/multimodal_attributes.md:244-246say the flags hide message text "including message documentdocument.content" and say nothing about tool call arguments.- The
hide_input_text/hide_output_textfield docstrings atconfig.py:221,229say the same. go/openinference-instrumentation/README.md:71,77says the flag "redacts only.content" and "Matches PythonTraceConfig.maskbehavior exactly", which is now false.
- JS and Go don't redact arguments: JS
maskingRules.tsonly redactsmessage.contentandmessage_content.text, and Go only appliesMaskInputText/MaskOutputTextto content. So the sameOPENINFERENCE_HIDE_INPUT_TEXT=truenow hides tool arguments in Python and leaves them visible in JS and Go.
Fix: add the tool_call.function.arguments / message.function_call_arguments_json leaves to the spec rows, multimodal_attributes.md § Hiding Text Content and the two docstrings, and correct the Go README line. Then either mark the behavior Python-only in the spec, as HIDE_RETRIEVAL_DOCUMENTS is, or track matching JS and Go rules as a follow-up.
|
The factory recommends Request changes for 19b6400. Read the review. |
… call args The core TraceConfig change in Arize-ai#4048 extends hide_input_text/hide_output_text to redact tool call arguments (tool_calls.*.tool_call.function.arguments and the legacy function_call_arguments_json leaf). The openai and vertexai instrumentor test helpers still asserted the raw arguments regardless of the hide_text flag, which the factory bot flagged as a blocking regression: - ci-openai: test_chat_completions_with_config_hiding_hiding_outputs[True-False-False] expected raw function_call.arguments but got __REDACTED__ - ci-vertexai: test_instrumentor_config_hiding_outputs[True-False-False] tried json.loads on the __REDACTED__ marker The call id and function name remain visible; only the arguments payload is redacted, matching the documented scope of the text-hiding flags. Local verification: - openai hiding_outputs: 8 passed (was 1 failed/7 passed) - vertexai config_hiding_outputs: 8 passed (was 1 failed/7 passed) - core openinference-instrumentation tests/test_config.py: 8274 passed
… flags Follow-up to the factory non-blocking note: the Python mask() already redacts message.function_call_arguments_json and message.tool_calls.*.tool_call.function.arguments_json when hide_input_text/hide_output_text is set, but the field docstrings, configuration spec, multimodal spec and Go README still described only message document content. Update them to state the new behavior and mark the tool-call-arguments coverage as Python-only (Go/JS do not redact tool call arguments). No behavior change.
|
The factory started a review of 3a6ed22 (session |
There was a problem hiding this comment.
Factory review of 3a6ed22: Approve
All criteria pass: the two instrumentor tests the last round flagged are fixed, every Python check run here passes, and there are no blocking findings.
| Criterion | Result | Notes |
|---|---|---|
| Fit | Pass | does what it claims |
| Checks | Not run | Python envs pass; spec/ and Go README have no sandbox checks |
| Tests | Pass | all 6 new redaction cases and the openai/vertexai edits fail without the change |
| Blocking findings | 0 | |
| Non-blocking findings | 2 | docs name wrong key config.py:223; contents.* path untested test_config.py:438 |
| Risk | Medium | backwards compatibility: opt-in text flags now also hide tool arguments |
| Review depth | Deep | touches the openinference-instrumentation core and spec/; Risk Medium |
Details
Intent: Make TraceConfig.hide_input_text / hide_output_text also redact tool call arguments in input/output messages (…message.tool_calls.<j>.tool_call.function.arguments and legacy …message.function_call_arguments_json), leaving the call id and function name visible.
Fit: Two new elif branches in TraceConfig.mask plus _is_tool_call_arguments do this, scoped to llm.<input|output>_messages keys.
They come after the hide_inputs/hide_*_messages early returns, so dropping messages still wins.
Bare TOOL-span tool_call.function.arguments, llm.tools.*, tool.parameters and input.value are untouched.
gen_ai.* is derived from the masked attributes, so the redaction carries through.
This push updates the openai and vertexai hiding tests the previous review flagged and documents the behavior as Python-only in spec/ and the Go README, as that review suggested.
The diff changes nothing the PR doesn't claim.
Verified:
- 24 tox envs pass, run in parallel on Python 3.11:
ci-instrumentation,ci-openai,ci-vertexai,ci-anthropic,ci-groq,ci-instructor,ci-langchain,ci-llama_index,ci-openai_agents,ci-strands_agents,ci-google_genai,ci-bedrock,ci-litellm,ci-portkey,ci-together,ci-ollama,ci-cohere,ci-agno,ci-google_adk,ci-ag2,ci-claude_agent_sdk,ci-crewai,ci-typesafeandci-pipecat. - With the base
config.pyswapped into the installed envs, the PR's tests fail as expected. Intest_config.py, 6 fail: the 4test_trace_configredaction cases and bothtest_text_hiding_covers_helper_emitted_tool_call_argumentscases. The function-name and unset-flag guard cases pass either way.test_chat_completions_with_config_hiding_hiding_outputs[True-False-False](openai) andtest_instrumentor_config_hiding_outputs[True-False-False](vertexai) also fail. With the PR'sconfig.py, all of them pass.
Not verified: - These instrumentor envs, which CI runs because the core changed: mistralai, dspy, guardrails, haystack, smolagents, autogen, autogen_agentchat, beeai, mcp, pydantic_ai, openllmetry, openlit, agent_framework and agentspec. None of their tests reference the text-hiding flags.
- The
-latestandopenai-v3variants, and py3.10/py3.14: the sandbox has only Python 3.11. spec/and the Go README changes were reviewed by reading only.
Findings without a diff line: none
Risk: side effects low, performance none, backwards compatibility medium: users who already sethide_*_textwill now see__REDACTED__for tool call arguments, and Python now differs from Go and JS under the same env vars (documented). Ratings from the Python reviewer.
Graded against the review criteria.
| """Hides text from input messages, including message document content""" | ||
| """Hides text from input messages, including message document content and | ||
| tool call arguments (``message.function_call_arguments_json`` and | ||
| ``message.tool_calls.*.tool_call.function.arguments_json``)""" |
There was a problem hiding this comment.
Non-blocking. The new docs name an attribute key that doesn't exist: message.tool_calls.*.tool_call.function.arguments_json.
Evidence:
- The real key is
tool_call.function.arguments. In semconv__init__.py:633,ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON = "tool_call.function.arguments".spec/semantic_conventions.md:150and:417use the same spelling, and so do the PR body and_is_tool_call_arguments. - The wrong spelling appears in five places: here at lines 223 and 233,
spec/configuration.md:18and:20, andspec/multimodal_attributes.md:246. spec/is normative, so anyone who searches for…arguments_jsonon a span finds nothing.
Fix: change tool_call.function.arguments_json to tool_call.function.arguments in all five places. message.function_call_arguments_json is correct and can stay. Because _is_tool_call_arguments uses endswith, it also redacts message.contents.*.tool_call.function.arguments (the tool_use content-item path in spec/semantic_conventions.md:404), so list that path as well.
| "hide_input_text", | ||
| True, | ||
| f"{SpanAttributes.LLM_INPUT_MESSAGES}.0.{MessageAttributes.MESSAGE_TOOL_CALLS}" | ||
| f".0.{ToolCallAttributes.TOOL_CALL_FUNCTION_NAME}", |
There was a problem hiding this comment.
Non-blocking. One path the change redacts has no test: llm.<input|output>_messages.N.message.contents.M.tool_call.function.arguments.
Evidence:
_is_tool_call_argumentsusesendswith, so it matches this key too.- litellm's Anthropic messages path emits it (
_anthropic_messages_attributes.py:83). - Narrowing the matcher to
.tool_calls.would drop that redaction, and no test would fail. - The
TOOL_CALL_FUNCTION_NAMEcase here passes with or without the change, so it only guards against over-redaction.
I confirmed that the six hiding cases and both helper tests fail with the base config.py and pass with this one.
Fix: add hide_input_text and hide_output_text cases for f"{LLM_*_MESSAGES}.0.{MessageAttributes.MESSAGE_CONTENTS}.0.{ToolCallAttributes.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}" → REDACTED_VALUE. Also add a negative case showing that a bare tool_call.function.arguments key (as on a TOOL span) stays visible.
|
The factory recommends Approve for 3a6ed22 and labeled this pull request |
Summary
hide_input_text/hide_output_textare documented as hiding text from input/outputmessages, but
TraceConfig.maskonly matchedmessage.contentandmessage_content.text. The tool call arguments leaf — the key thatget_llm_input_message_attributes/get_llm_output_message_attributesemit, and that theprovider instrumentors write — was never matched, so the arguments JSON was exported in full
with the text hiding flags enabled:
llm.<input|output>_messages.<i>.message.tool_calls.<j>.tool_call.function.argumentsllm.<input|output>_messages.<i>.message.function_call_arguments_jsonThis extends both flags to the arguments leaf of a tool call. The call's id and function name
are untouched, so span structure (which tool was called, and with which call id) is preserved.
Testing
tests/test_config.py::test_trace_configplustest_text_hiding_covers_helper_emitted_tool_call_arguments: the 6 new cases fail onmain(raw arguments returned instead of__REDACTED__) and pass with the change.tests/test_config.py: 8232 passed. The package's non-network test set(config, blob upload, context managers, genai, annotations, projects, tracer providers,
helpers, id generator): 8372 passed.
ruff check,ruff format --diff,mypy src: clean.AI disclosure
AI-assisted change. The gap was found by an AI pass over
openinference-instrumentation'smasking matrix; the fix and the regression tests were drafted with AI assistance, then
reproduced and verified locally (red before the change, green after) before submission.