Skip to content

Scrub nested keys in GenAI content - #2823

Merged
alexmojaki merged 6 commits into
mainfrom
codex/genai-structured-key-scrubbing
Nov 18, 2026
Merged

alexmojaki merged 6 commits into
mainfrom
codex/genai-structured-key-scrubbing

Conversation

@alexmojaki

@alexmojaki alexmojaki commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a key-only pattern matching mode for structured GenAI and Pydantic AI messages, while continuing to transform their string values.
  • Apply it to GenAI input and output messages, system instructions, and pydantic_ai.all_messages, including tool calls nested within those messages.
  • Preserve existing value-based pattern matching for standalone tool-call arguments and results, and the existing pattern exemption for tool definitions.
  • Allow user-supplied patterns to match the outer attribute name and redact its complete value.

This is PR 1 of the scrubbing-policy split. Provider scope handling and other Pydantic AI attributes remain separate.

Verification

  • uv run pytest -q -p no:cacheprovider tests/test_secret_scrubbing.py (82 passed)
  • Ruff, Ruff Format, and pyright passed in commit hooks.

@veria-ai

veria-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Reviews

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

View guided diff | Re-trigger cubic

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  logfire-sdk/logfire/_internal
  scrubbing.py
Project Total  

This report was generated by python-coverage-comment-action


# Message content can contain sensitive named fields alongside prose where
# matching the string value would produce false positives.
KEY_ONLY_KEYS = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make the meanings of the three sets very clear, explain how they differ and why. should KEY_ONLY_KEYS be a subset of safe keys?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(AI) Addressed in b7c3c54. KEY_ONLY_KEYS is now explicitly included in SAFE_KEYS, and comments define the three policies and their precedence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

KEY_ONLY_KEYS is now explicitly included in SAFE_KEYS

but should it be? why or why not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(AI) Yes, with the current meaning of SAFE_KEYS. SpanScrubber exempts the outer attribute name, while KEY_ONLY_KEYS changes how its descendants are searched: nested keys match, string values do not. MessageValueCleaner also uses SAFE_KEYS to pass safe-named fields through scrub_value as a mapping; if a GenAI key were outside SAFE_KEYS and check_keys=False, it would pass the string directly and run value patterns on prose. The subset encodes that exemption. The name SAFE_KEYS is overloaded, but making the sets disjoint would require changing that caller too.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@alexmojaki
alexmojaki added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 2c36017 Nov 18, 2026
32 checks passed
@alexmojaki
alexmojaki deleted the codex/genai-structured-key-scrubbing branch November 18, 2026 11:15
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.

1 participant