Skip to content

feat(security): filter sensitive data from tool results before sending to LLM#1930

Merged
yinwm merged 2 commits intosipeed:mainfrom
uiYzzi:feat/filter-sensitive-data-from-tool-results
Mar 23, 2026
Merged

feat(security): filter sensitive data from tool results before sending to LLM#1930
yinwm merged 2 commits intosipeed:mainfrom
uiYzzi:feat/filter-sensitive-data-from-tool-results

Conversation

@uiYzzi
Copy link
Copy Markdown
Contributor

@uiYzzi uiYzzi commented Mar 23, 2026

Summary

  • feat(security): add sensitive data filtering for tool results sent to LLM

Prevent the LLM from seeing its own credentials (API keys, tokens, secrets) by filtering sensitive values from tool call results before sending to the model. Values are collected from .security.yml and replaced with [FILTERED] using an efficient strings.Replacer (O(n+m)).

Changes

  • Add FilterSensitiveData bool and FilterMinLength int to ToolsConfig (default: enabled, min length 8)
  • Implement SensitiveDataReplacer() with sync.Once caching in SecurityConfig
  • Use reflection to collect all sensitive values: Model API keys, channel tokens (Telegram, Discord, Slack, Matrix, etc.), web tool API keys (Brave, Tavily, Perplexity), skills tokens (GitHub, ClawHub)
  • Apply filtering in agent loop at 4 tool result locations
  • Add comprehensive tests covering all token types (13 test cases)
  • Add bilingual documentation (English + Chinese)

Test plan

  • go test ./pkg/config/... — all filter-sensitive-data tests pass
  • go test ./pkg/tools/... — tools tests pass
  • go build ./pkg/... — pkg builds successfully

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update

AI Code Generation

  • 🤖 Fully AI-generated
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written

uiYzzi added 2 commits March 23, 2026 20:55
LLM

Prevent LLM from seeing its own credentials (API keys, tokens, secrets)
by filtering sensitive values from tool call results before sending to
the
model. Values are collected from .security.yml and replaced with
[FILTERED] using an efficient strings.Replacer (O(n+m)).

- Add FilterSensitiveData and FilterMinLength to ToolsConfig
- Implement SensitiveDataReplacer() with sync.Once caching in
  SecurityConfig
- Use reflection to collect all sensitive values (Model API keys,
  channel
  tokens, web tool API keys, skills tokens)
- Apply filtering in agent loop at 4 tool result locations
- Add comprehensive tests covering all token types
@sipeed-bot sipeed-bot Bot added type: enhancement New feature or request domain: config domain: agent go Pull requests that update go code labels Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@yinwm yinwm left a comment

Choose a reason for hiding this comment

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

LGTM! This is a well-designed security enhancement. The code quality is high, tests are comprehensive (13 test cases), documentation is complete (EN + CN), and all CI checks pass.

Key highlights:

  • Efficient O(n+m) implementation using strings.Replacer
  • Smart use of reflection to auto-collect all sensitive values
  • Lazy initialization with sync.Once
  • Flexible configuration with sensible defaults

Minor suggestions for future improvement (non-blocking):

  • Add debug logging for filter operations
  • Make replacement string [FILTERED] configurable
  • Consider caching optimization for large configs

Merging now. Thanks @uiYzzi!

@yinwm yinwm merged commit 4057199 into sipeed:main Mar 23, 2026
4 checks passed
andressg79 pushed a commit to andressg79/picoclaw that referenced this pull request Mar 30, 2026
…-from-tool-results

feat(security): filter sensitive data from tool results before sending to LLM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: agent domain: config go Pull requests that update go code type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants