Skip to content

🔒 feat: Privacy Controls for Langfuse Trace Content - #15027

Open
berry-13 wants to merge 6 commits into
devfrom
berry-13/enhancement-add-privacy-controls-to-suppress-or
Open

berry-13 wants to merge 6 commits into
devfrom
berry-13/enhancement-add-privacy-controls-to-suppress-or

Conversation

@berry-13

@berry-13 berry-13 commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Langfuse tracing exported conversation content, tool arguments and outputs, trace metadata, and media with no way to suppress any of it, which blocks deployments that need operational telemetry (latency, model, token usage, cost, errors) without conversation content leaving the server. Resolves #14362.

This adds a langfuse.privacy block to librechat.yaml with a mode (full default, or metricsOnly) and a configurable redactionText. In metricsOnly, message content, tool arguments, tool outputs, and trace/observation metadata are replaced with the redaction marker before trace data leaves the server on every export destination, media upload is disabled, and tenant trace metadata and tags are skipped at the source. Trace structure, timing, model, token usage, cost, and error status remain available.

The policy fails closed: when the installed @librechat/agents runtime cannot enforce masking, trace export is disabled for the run and the operator is warned once per process. Masking is enforced by the tracing runtime in LibreChat-AI/agents#440, which no @librechat/agents release includes yet (4.0.1, the latest, does not); merging earlier is safe because of the fail-closed gate. The redacted mode from the issue is not accepted by the schema yet, since no rules engine exists.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • cd packages/data-provider && npx jest specs/config-schemas.spec.ts: 108 passed
  • cd packages/api && npx jest src/langfuse/: config 49, policy 16, feedback suites green
  • cd packages/api && npx jest src/admin/secrets.spec.ts src/admin/config.handler.spec.ts: 190 passed
  • cd api && npx jest server/services/Config/loadCustomConfig.spec.js: 22 passed
  • cd packages/api && npx tsc --noEmit -p tsconfig.json, plus eslint on touched files

Manual checks: schema accepts metricsOnly and rejects unknown modes and blank redaction text; buildLangfuseConfig attaches the policy with trimmed redaction text, suppresses tenant metadata and tags, and produces a full export in full mode; the fail-closed path disables export when the runtime lacks the capability export. Not run: a live round-trip against a real Langfuse instance (the masking path is verified in LibreChat-AI/agents#440 against the real span processor).

Test Configuration:

Node v24.16.0, local MongoDB, @librechat/agents 4.0.1 installed (exercises the fail-closed path), agents branch built locally for the supported-path unit tests.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Copilot AI lite review requested due to automatic review settings August 20, 2026 12:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31694e79bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/langfuse/config.ts

Copilot AI 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.

Pull request overview

This PR adds configurable privacy controls to the Langfuse tracing integration so operators can keep operational telemetry (timing/model/usage/cost/errors) while preventing conversation/tool/media content from being exported off-server, with a fail-closed safeguard when the installed tracing runtime can’t enforce masking.

Changes:

  • Extends librechat.yaml Langfuse config schema with a new langfuse.privacy block (full | metricsOnly, optional redactionText).
  • Adds backend policy/config plumbing to attach metricsOnly privacy to the Langfuse run config and disable export when masking support is unavailable.
  • Adds/updates Jest coverage and documents the new config in librechat.example.yaml.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/data-provider/src/config.ts Adds langfuse.privacy config schema to validate privacy mode and redaction marker.
packages/data-provider/specs/config-schemas.spec.ts Validates the new schema behavior via config schema unit tests.
packages/api/src/langfuse/policy.ts Detects whether the installed @librechat/agents runtime supports privacy masking (capability probe).
packages/api/src/langfuse/policy.spec.ts Tests the capability probe behavior via mocked agents runtime exports.
packages/api/src/langfuse/config.ts Attaches metricsOnly privacy policy to run config and fails closed when unsupported.
packages/api/src/langfuse/config.spec.ts Adds unit tests for metricsOnly attachment and fail-closed behavior.
librechat.example.yaml Documents the new langfuse.privacy configuration block for operators.
Suppressed comments (2)

packages/api/src/langfuse/config.spec.ts:965

  • New test case uses as unknown as AppConfig. Since AppConfig has a small required core shape, prefer constructing a minimal AppConfig object directly (avoids as unknown as T per CLAUDE.md Type Safety guidance).
          appConfig: {
            langfuse: { privacy: { mode: 'metricsOnly' } },
          } as unknown as AppConfig,
        }),

packages/api/src/langfuse/config.spec.ts:987

  • New test adds another as unknown as AppConfig assertion. Consider using a minimal AppConfig literal (with config, fileStrategy, imageOutputType) to keep tests type-safe without the double cast.
      appConfig: {
        langfuse: { privacy: { mode: 'full' } },
      } as unknown as AppConfig,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/data-provider/src/config.ts
Comment thread packages/data-provider/specs/config-schemas.spec.ts
Comment thread packages/api/src/langfuse/config.spec.ts
@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 31694e79bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 906b37448f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 3a80a3f2da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@berry-13
berry-13 marked this pull request as draft August 20, 2026 22:56
@berry-13
berry-13 marked this pull request as ready for review September 1, 2026 17:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-01T17:24:27.778863Z 3a80a3f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danny-avila danny-avila added area/LLM provider integration and observability 🗺️ Observability codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) and removed area/LLM provider integration and observability labels Sep 24, 2026
Langfuse tracing exported conversation content, tool arguments and
outputs, trace metadata, and media with no way to suppress any of it,
which blocks deployments under GDPR-style data-protection requirements
that want operational telemetry without conversation content.

Add a langfuse.privacy block to librechat.yaml. mode metricsOnly replaces
message, tool, and metadata content with a redaction marker on every
export destination and disables media upload, while trace structure,
timing, model, token usage, cost, and error status stay exported. Tenant
trace metadata and tags are skipped at the source in that mode since the
SDK mask does not cover tags.

The policy fails closed: when the installed @librechat/agents runtime
cannot enforce masking (detected through its
LANGFUSE_PRIVACY_MASKING_SUPPORTED export), trace export is disabled for
the run and the operator is warned once, rather than degrading into a
full export.

Closes #14362
Review follow-up: metricsOnly now also applies to Langfuse feedback
scores. The score comment (feedback tag and free text) is omitted, the
tag and the sender display name are dropped from score metadata, and the
rating plus correlation ids stay. Also trim langfuse.privacy.redactionText
in the schema so whitespace-only values are rejected at load instead of
silently falling back to the default marker at runtime.

The feedback comment separator changes from an em dash to a colon.
@codegraph-librechat codegraph-librechat Bot added the 🗺️ Backend Platform codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 1, 2026
@berry-13
berry-13 force-pushed the berry-13/enhancement-add-privacy-controls-to-suppress-or branch from 3a80a3f to ca99b84 Compare October 2, 2026 08:44
@berry-13

berry-13 commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 5d29cde. State the exact reviewed commit and ignore findings that apply only to earlier heads.

Purpose supplied by the requester: Head 5d29cde never reviewed: rebase onto dev plus 302d64e (metricsOnly suppresses trace identity fields) and 2 e2e spec commits since reviewed head 3a80a3f

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d29cde9ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/langfuse/policy.ts
@codegraph-librechat codegraph-librechat Bot added 🗺️ Server Core codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Backend Infra codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) labels Oct 3, 2026

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

🗺️ Backend Infra codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Backend Platform codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Observability codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Server Core codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants