Skip to content

Redaction ​

API keys, tokens and PII are redacted before they leave your process, on by default. redactConfig adds your own terms or tunes flare-redact's detectors, and redactConfig: false turns redaction off.

ts
import { z } from 'zod/v4'
import { trypatch } from '@ssandir/trypatch'

const CustomerSchema = z.object({
    id: z.string(),
    name: z.string(),
    tier: z.enum(['free', 'pro', 'enterprise']),
})
type Customer = z.infer<typeof CustomerSchema>

export class CustomerRepository {
    @trypatch({
        aiInvestigation: {
            resultSchema: CustomerSchema,
            investigationProvider: {
                provider: 'openai',
                apiKey: process.env.OPENAI_API_KEY!,
            },
            // Redacted on top of what flare-redact's detectors find
            redactConfig: {
                terms: [process.env.DB_PASSWORD!, process.env.INTERNAL_SERVICE_TOKEN!],
            },
        },
    })
    async getCustomer (customerId: string): Promise<Customer> {
        // Even if the password appears in the error, it won't reach OpenAI
        const [row] = await db.query('SELECT id, name, tier FROM customers WHERE id = $1', [customerId])
        return CustomerSchema.parse(row)
    }
}

How it works ​

  1. Before the prompt goes to the provider, trypatch replaces secrets found by flare-redact's default detectors (API keys, bearer tokens, emails, card numbers, ...) and your terms with placeholders.
  2. The provider investigates the redacted data.
  3. When the AI calls an investigation or MCP tool, placeholders in its input are restored before the tool runs, and the tool's output is redacted before it goes back.
  4. Placeholders in the response are restored locally before the value is returned.

Detected and listed secrets never leave your infrastructure.

What isn't redacted ​

Redaction only covers what goes to the provider:

  • Callbacks get raw values: ctx.error and ctx.args as they were, and the AI's explanation with placeholders restored. Scrub them before they reach a third party.
  • Tool and MCP tool descriptions are sent as written.
  • With cursor, MCP traffic runs inside Cursor, out of redaction's reach. See MCP servers.
  • To keep values out of the prompt entirely, use sanitizeArgs.