From a9f25b1d31ab8c7d71a87c2839f9ee98d188bc0a Mon Sep 17 00:00:00 2001 From: li4nee Date: Sat, 28 Nov 2026 22:48:18 +0545 Subject: [PATCH] feat: add per-bot PII redaction controls Signed-off-by: li4nee --- README.md | 1 + apps/admin/src/features/bots/bots.spec.tsx | 14 +++ .../bots/components/bot-behavior-form.tsx | 57 ++++++++- .../knowledge/test-retrieval-panel.spec.tsx | 1 + apps/api/src/common/pii-redaction.spec.ts | 32 ++++++ apps/api/src/common/pii-redaction.ts | 57 +++++++++ .../migrations/1794880000000-pii-redaction.ts | 16 +++ .../agent-assist/handoff-summary.processor.ts | 16 ++- .../agent-assist/reply-suggestions.service.ts | 13 ++- apps/api/src/modules/bots/bot.entity.ts | 6 +- apps/api/src/modules/bots/bots.mapper.ts | 1 + apps/api/src/modules/bots/bots.service.ts | 5 + .../chat/chat-orchestrator.int.spec.ts | 31 +++++ .../api/src/modules/chat/chat-orchestrator.ts | 108 ++++++++++++------ .../modules/chat/chat-persistence.service.ts | 15 ++- .../modules/chat/domain/prompt-assembly.ts | 7 ++ .../conversations/agent-actions.service.ts | 7 +- .../conversations/conversations.module.ts | 3 +- .../integrations/crm-context.processor.ts | 16 ++- apps/docs/src/content/docs/data-handling.md | 13 ++- apps/docs/src/content/docs/security.md | 3 + docs/spec.md | 2 +- .../plans/2026-11-28-m27-privacy-controls.md | 96 ++++++++++++++++ packages/shared/src/bots.ts | 3 + packages/shared/src/index.ts | 5 + packages/shared/src/privacy.spec.ts | 19 +++ packages/shared/src/privacy.ts | 9 ++ 27 files changed, 495 insertions(+), 61 deletions(-) create mode 100644 apps/api/src/common/pii-redaction.spec.ts create mode 100644 apps/api/src/common/pii-redaction.ts create mode 100644 apps/api/src/db/migrations/1794880000000-pii-redaction.ts create mode 100644 docs/superpowers/plans/2026-11-28-m27-privacy-controls.md create mode 100644 packages/shared/src/privacy.spec.ts create mode 100644 packages/shared/src/privacy.ts diff --git a/README.md b/README.md index 23863853..b7bbd917 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - **A complete support flow:** embed a branded widget with citations, handoff, feedback, cards, carousels, quick replies, and bounded forms. - **A team inbox:** route work with agent presence, capacity limits, and response or resolution targets. - **Operational visibility:** review knowledge gaps, model use, cost, latency, prompt releases, and retrieval evaluations. +- **Privacy controls:** choose whether email, phone, payment-card, and credential values are redacted from new transcripts and before AI or tool requests. - **Self-hosted by design:** run on PostgreSQL with pgvector and connect a supported hosted or local model provider. ## See the product diff --git a/apps/admin/src/features/bots/bots.spec.tsx b/apps/admin/src/features/bots/bots.spec.tsx index b61c1b9d..9319e79e 100644 --- a/apps/admin/src/features/bots/bots.spec.tsx +++ b/apps/admin/src/features/bots/bots.spec.tsx @@ -58,6 +58,7 @@ const BOT: BotDto = { rerankingEnabled: false, queryRewritingEnabled: false, answerVerificationEnabled: false, + piiRedactionCategories: [], noAnswerBehavior: 'offer_handoff', handoffEnabled: true, automaticHandoffSummaries: false, @@ -341,6 +342,19 @@ describe('BotModelForm', () => { }); describe('BotBehaviorForm', () => { + it('saves the selected privacy redaction categories', async () => { + const calls = mockApi(botRoutes()); + renderWithQuery(asRole(ADMIN, )); + + await userEvent.click(await screen.findByRole('checkbox', { name: 'Email addresses' })); + await userEvent.click(screen.getByRole('button', { name: strings.bots.save })); + + await screen.findByText(strings.bots.saved); + expect(calls.find((call) => call.method === 'PATCH')?.body).toMatchObject({ + piiRedactionCategories: ['email'], + }); + }); + it('lets an admin opt the bot into privacy-aware follow-up query rewriting', async () => { const calls = mockApi(botRoutes()); renderWithQuery(asRole(ADMIN, )); diff --git a/apps/admin/src/features/bots/components/bot-behavior-form.tsx b/apps/admin/src/features/bots/components/bot-behavior-form.tsx index fa46166a..ee9e638a 100644 --- a/apps/admin/src/features/bots/components/bot-behavior-form.tsx +++ b/apps/admin/src/features/bots/components/bot-behavior-form.tsx @@ -11,7 +11,12 @@ import { Label } from '@/components/ui/label'; import { Skeleton } from '@/components/ui/skeleton'; import { errorMessage } from '@/lib/error-message'; import { strings } from '@/strings'; -import { NO_ANSWER_BEHAVIORS, type NoAnswerBehavior } from '@app/shared'; +import { + NO_ANSWER_BEHAVIORS, + PII_REDACTION_CATEGORIES, + type NoAnswerBehavior, + type PiiRedactionCategory, +} from '@app/shared'; import { useBot, useUpdateBot } from '../api'; import { normalizeOrigins } from '../origin'; @@ -33,6 +38,9 @@ export function BotBehaviorForm({ workspaceId, botId }: { workspaceId: string; b const [rerankingEnabled, setRerankingEnabled] = useState(null); const [queryRewritingEnabled, setQueryRewritingEnabled] = useState(null); const [answerVerificationEnabled, setAnswerVerificationEnabled] = useState(null); + const [piiRedactionCategories, setPiiRedactionCategories] = useState< + PiiRedactionCategory[] | null + >(null); const [temperature, setTemperature] = useState(null); const [maxOutputTokens, setMaxOutputTokens] = useState(null); const [dailySpendCap, setDailySpendCap] = useState(null); @@ -67,6 +75,7 @@ export function BotBehaviorForm({ workspaceId, botId }: { workspaceId: string; b rerankingEnabled: rerankingEnabled ?? data.rerankingEnabled, queryRewritingEnabled: queryRewritingEnabled ?? data.queryRewritingEnabled, answerVerificationEnabled: answerVerificationEnabled ?? data.answerVerificationEnabled, + piiRedactionCategories: piiRedactionCategories ?? data.piiRedactionCategories, temperature: Number(temperature ?? data.temperature), maxOutputTokens: Number(maxOutputTokens ?? data.maxOutputTokens), dailySpendCapUsd: @@ -231,9 +240,10 @@ export function BotBehaviorForm({ workspaceId, botId }: { workspaceId: string; b

Off by default. When enabled, the configured chat provider receives up to two recent - visitor messages after basic email, phone, and long-number redaction. The request is used - only to form a search query; it is not saved in traces. A timeout or invalid result keeps - the original search query. Provider usage may add cost. + visitor messages after basic email, phone, and long-number redaction. Privacy categories + selected below also apply across model requests. The rewrite request is used only to form + a search query and is not saved in traces. A timeout or invalid result keeps the original + search query. Provider usage may add cost.