Skip to main content

Guardian Layer Client

GuardianLayer detects and de-identifies PII/PHI in text and files. Use it directly, or set privacyEnabled: true on a Custodian Agent to run the same masking automatically during chat.

Concepts: Guardian Layer overview.

import { GuardianLayer } from "@custodianlabs/sdk";

const guardian = new GuardianLayer();
OptionDefault
apiKeyCUSTODIAN_SDK_API_KEY
baseUrlCUSTODIAN_MASKING_BASE_URLhttps://privacy.custodianlabs.io
timeout60 s
maxRetries2

De-identify text

const result = await guardian.deidentifyTextOutputs("John Smith, 617-555-0100", {
maskingType: "transform", // or "redact"
piiEntities: ["PERSON", "PHONE_NUMBER"], // omit for all
});

for (const item of result.outputs) console.log(item.id, item.text);

outputs holds one or two candidates. result.originalText is the input.

deidentifyText() is the single-output variant and accepts replacements: { orig: "new" } to pin specific swaps.

Detect only

const result = await guardian.analyzeProprietary("John Smith lives in Boston.");
console.log(result.sensitiveWords); // ["John Smith", "Boston"]

Returns the flagged terms without changing the text.

De-identify files

import { writeFile } from "node:fs/promises";

// dispatches by extension: csv, xlsx, xls, docx, pdf, txt
const result = await guardian.deidentifyFile("./customers.csv", { maskingType: "transform" });

console.log(result.filename, result.mediaType);
await writeFile(result.filename ?? "output.csv", result.content);

Explicit methods: deidentifyCsv, deidentifyDocx, deidentifyPdf, deidentifyTxt. Each takes a FileInput — a path (Node) or { data, filename, contentType? } for browser / edge.

MaskedFileResult: content (Uint8Array), filename, mediaType, statusCode, text(encoding?).

Errors

Same typed errors as the rest of the SDK — see Error Handling.

Next

Guardian Layer overview · Guide: De-identify text