Skip to content

fix(instrumentation): redact tool call arguments with the text hiding flags - #4048

Open
RichardoMrMu wants to merge 5 commits into
Arize-ai:mainfrom
RichardoMrMu:fix-tool-call-arguments-text-hiding
Open

RichardoMrMu wants to merge 5 commits into
Arize-ai:mainfrom
RichardoMrMu:fix-tool-call-arguments-text-hiding

Conversation

@RichardoMrMu

@RichardoMrMu RichardoMrMu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

hide_input_text / hide_output_text are documented as hiding text from input/output
messages, but TraceConfig.mask only matched message.content and
message_content.text. The tool call arguments leaf — the key that
get_llm_input_message_attributes / get_llm_output_message_attributes emit, and that the
provider 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.arguments
  • the legacy spelling llm.<input|output>_messages.<i>.message.function_call_arguments_json

This 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

  • New parametrized cases in tests/test_config.py::test_trace_config plus
    test_text_hiding_covers_helper_emitted_tool_call_arguments: the 6 new cases fail on
    main (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's
masking 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.

… 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
@RichardoMrMu

Copy link
Copy Markdown
Contributor Author

@mikeldking @sanchitram1 could you approve the fork workflows on this PR? Nothing has run on this branch yet.

@mikeldking mikeldking self-assigned this Oct 22, 2026
# Conflicts:
#	python/openinference-instrumentation/tests/test_config.py
@mikeldking mikeldking added the factory-review to be reviewed by the software factory label Oct 31, 2026 — with Claude
@openinference-factory

Copy link
Copy Markdown
Contributor

The factory started a review of 19b6400 (session sesn_01EiisCRSNivFTBhFj3tgUTE). It reports back here when the session ends.

@openinference-factory openinference-factory Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-instrumentation passes: ruff format, ruff check, mypy, 8599 tests.
  • With the base config.py installed, the 6 new redaction cases fail (4 test_trace_config cases and both test_text_hiding_covers_helper_emitted_tool_call_arguments cases); with the PR they pass.
  • ci-openai fails test_chat_completions_with_config_hiding_hiding_outputs[True-False-False], and ci-vertexai fails test_instrumentor_config_hiding_outputs[True-False-False]. Both pass with the base config.py in the same envs.
  • ci-anthropic, ci-groq, ci-strands_agents, ci-instructor, ci-langchain, ci-llama_index and ci-openai_agents pass.
    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 -latest variants 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 set hide_*_text will now see __REDACTED__ for tool arguments in spans and gen_ai.*. Ratings from the Python reviewer.

Graded against the review criteria.

Comment on lines +429 to +440
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 at test_instrumentor.py:1599. It expects the raw message.function_call_arguments_json and gets AssertionError: assert '__REDACTED__' == '0.4360070478690712'.
  • tox run -e ci-vertexai: test_gapic_client.py::test_instrumentor_config_hiding_outputs[True-False-False] fails at test_gapic_client.py:511. json.loads(args_json_str) raises JSONDecodeError because tool_call.function.arguments is 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.

Comment on lines +597 to +605
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
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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,20 and spec/multimodal_attributes.md:244-246 say the flags hide message text "including message document document.content" and say nothing about tool call arguments.
    • The hide_input_text / hide_output_text field docstrings at config.py:221,229 say the same.
    • go/openinference-instrumentation/README.md:71,77 says the flag "redacts only .content" and "Matches Python TraceConfig.mask behavior exactly", which is now false.
  • JS and Go don't redact arguments: JS maskingRules.ts only redacts message.content and message_content.text, and Go only applies MaskInputText/MaskOutputText to content. So the same OPENINFERENCE_HIDE_INPUT_TEXT=true now 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.

@openinference-factory

Copy link
Copy Markdown
Contributor

The factory recommends Request changes for 19b6400. Read the review.

@openinference-factory openinference-factory Bot removed the factory-review to be reviewed by the software factory label Oct 31, 2026
@mikeldking mikeldking added the factory-request-changes The factory review recommends requesting changes label Oct 31, 2026
RichardoMrMu and others added 2 commits November 2, 2026 17:54
… 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.
@RichardoMrMu
RichardoMrMu requested a review from a team as a code owner November 2, 2026 16:24
@mikeldking mikeldking added the factory-review to be reviewed by the software factory label Nov 5, 2026
@openinference-factory openinference-factory Bot removed the factory-request-changes The factory review recommends requesting changes label Nov 5, 2026
@openinference-factory

Copy link
Copy Markdown
Contributor

The factory started a review of 3a6ed22 (session sesn_011PDZbtbG5fnSMeLEPaRHc2). It reports back here when the session ends.

@openinference-factory openinference-factory Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-typesafe and ci-pipecat.
  • With the base config.py swapped into the installed envs, the PR's tests fail as expected. In test_config.py, 6 fail: the 4 test_trace_config redaction cases and both test_text_hiding_covers_helper_emitted_tool_call_arguments cases. The function-name and unset-flag guard cases pass either way. test_chat_completions_with_config_hiding_hiding_outputs[True-False-False] (openai) and test_instrumentor_config_hiding_outputs[True-False-False] (vertexai) also fail. With the PR's config.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 -latest and openai-v3 variants, 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 set hide_*_text will 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``)"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:150 and :417 use 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:18 and :20, and spec/multimodal_attributes.md:246.
  • spec/ is normative, so anyone who searches for …arguments_json on 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}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_arguments uses endswith, 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_NAME case 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.

@openinference-factory

Copy link
Copy Markdown
Contributor

The factory recommends Approve for 3a6ed22 and labeled this pull request factory-approved. Read the review.

@openinference-factory openinference-factory Bot added factory-approved The factory review recommends approving and removed factory-review to be reviewed by the software factory labels Nov 5, 2026
@caroger
caroger requested a review from RogerHYang November 5, 2026 19:02
@caroger caroger assigned RogerHYang and unassigned mikeldking Nov 5, 2026
@RichardoMrMu
RichardoMrMu requested review from a team as code owners November 26, 2026 02:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

factory-approved The factory review recommends approving

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants