Skip to content
Reading documents 7 min read · LogicSpoke PDF

Redacting PII before AI document processing: a practical guide

TL;DR: Add \"redact\": true to any parse request. Common PII patterns (SSN, email, phone, card numbers, and more) are detected and stripped before the text reaches the AI model or gets stored — using regex-based pattern matching, not a claim of exhaustive PII discovery. Detection also runs on every request by default, whether or not you redact.

If you're building in healthcare, legal, insurance, or HR, you hit the same wall at the same point in your architecture design: "I need to extract structured data from these documents — but they're full of PII I can't send to a third-party AI without controls."

This is the right instinct. Sending raw patient records, SSNs, or financial account details through an AI extraction API without any redaction step is a compliance risk worth taking seriously.

A note on scope before we go further: what's described below is real and shipped today, but it's pattern-based detection (regex over known formats), not a claim of exhaustive or certified PII discovery, and not a claim that LogicSpoke itself is HIPAA or GDPR certified — no such formal certificate exists for either. Treat this as one real technical safeguard in a compliance program you're still responsible for building around it.

What PII appears in business documents

Healthcare / PHI-adjacent: Patient name + date/condition, date of birth, SSN, National Provider Identifier (NPI), ICD-10 codes, health plan beneficiary numbers.

Financial: Credit/debit card numbers, bank account and routing numbers, tax identification numbers.

General PII: Email addresses, phone numbers, postal addresses, passport-format numbers.

How PII handling works in the parse API

The pipeline runs in two phases:

  1. Detection (always on): Every document parsed is scanned for PII patterns and a piiDetected flag (true/false) is recorded against that parse. This runs regardless of whether you request redaction.
  2. Redaction (opt-in): When you set "redact": true, any detected PII is stripped from the extracted text before it's passed to the AI model for schema extraction, and before it's stored. The model sees a placeholder token in place of sensitive values, extracts your schema fields around those placeholders, and the stored/returned result never contains the original PII.

What's not exposed today: piiDetected is a boolean, not a structured report. There's currently no API response that lists which PII types were found, on which pages, or how many instances — that level of detail is computed internally during the scan but isn't surfaced through any endpoint yet. If your compliance workflow needs a itemized PII report (not just strip-and-continue), that's worth confirming with LogicSpoke support before you build against it.

The API call: redact and extract in one step

The endpoint takes a real file upload (multipart/form-data), not a JSON body with a file URL:

curl -X POST "https://api.logicspoke.com/pdf/v1/pdf/parse" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -F "[email protected]" \
     -F "redact=true" \
     -F 'schema={
       "type": "object",
       "required": ["appointmentDate", "referringPhysician", "primaryDiagnosis", "insurancePlan"],
       "properties": {
         "appointmentDate":    { "type": "string", "format": "date" },
         "referringPhysician": { "type": "string" },
         "primaryDiagnosis":   { "type": "string" },
         "icd10Code":          { "type": "string" },
         "insurancePlan":      { "type": "string" },
         "copayAmount":        { "type": "number" }
       }
     }'

Response (async — poll GET /v1/pdf/parse/jobs/{jobId}, or subscribe a webhook to parse.completed):

{ "success": true, "jobId": "job_abc123", "status": "pending" }

Once complete, the extracted data contains your schema fields, populated from whatever text remained after redaction removed the PII patterns found elsewhere in the document.

Detection patterns

Pattern-based, not ML-based — this means fast and predictable, but also means it can miss unusual formats or over-match on things that merely look like PII. Don't treat this table as an accuracy guarantee:

PII Type Pattern examples caught
SSN 123-45-6789 format
Email Standard email address format
Phone Common US formats
Credit card 13–16 digit numeric runs (not checksum-validated — a random 16-digit number would also match)
NPI 10-digit numeric sequences
ICD-10 Standard ICD-10 code format
Date of birth Dates near "DOB"/"Date of Birth"/"Born" labels, or common date formats
Address US-style street address patterns

Complete workflow (Node.js)

async function processPatientDocument(fileBuffer, fileName, patientId) {
  const form = new FormData();
  form.append('file', fileBuffer, fileName);
  form.append('redact', 'true');
  form.append('schema', JSON.stringify({ /* ... your schema ... */ }));

  const response = await fetch('https://api.logicspoke.com/pdf/v1/pdf/parse', {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${process.env.LOGICSPOKE_API_KEY}` },
    body: form
  });
  const { jobId } = await response.json();
  await auditLog.record({ event: 'document_parse_initiated', patientId, jobId, redactionRequested: true });
  return jobId;
}

// Webhook handler — register this URL once via POST /v1/webhooks, events: ["parse.completed"]
app.post('/hooks/parse-complete', async (req, res) => {
  const { jobId, piiDetected } = req.body;
  // Fetch the actual extracted data separately — the webhook payload confirms
  // completion and whether PII was detected, but not the result itself.
  const jobRes = await fetch(`https://api.logicspoke.com/pdf/v1/pdf/parse/jobs/${jobId}`, {
    headers: { 'Authorization': `Bearer ${process.env.LOGICSPOKE_API_KEY}` }
  });
  const { result } = await jobRes.json();
  await auditLog.record({ event: 'document_parsed', jobId, piiDetected });
  // Store extracted data — redacted, safe to persist
  await db.clinicalRecords.upsert({ sourceJobId: jobId, ...result.data });
  res.sendStatus(200);
});

Your data controls

  • Export all account data (Subject Access Requests): GET /v1/compliance/export — free on every account tier
  • Audit log: GET /v1/compliance/audit?from=2026-01-01&to=2026-11-01
  • Delete your account and its data: from your LogicSpoke account page (accounts.logicspoke.com/account — not callable with an API key) — purges uploaded documents, parse results, and security records. Credit/billing transaction records are the one exception: they're retained afterward as required by financial record-keeping law, referencing only your opaque account ID, not your name or email. This isn't a claim of total erasure — see Your data and privacy for the full picture.

Questions

Does redact: true remove PII from the stored parse result too?

Yes. The stored result (accessible via GET /v1/pdf/parse/jobs/{jobId}) reflects the redacted text — PII patterns are replaced with placeholders before storage, not just before the AI call.

Can I configure which PII types to detect/redact?

Currently, detection and redaction apply to all supported pattern types simultaneously — there's no per-type on/off switch today.

Is this HIPAA-compliant?

There's no such thing as a formal "HIPAA-compliant" certificate to earn — HIPAA compliance is a program built from a signed Business Associate Agreement (BAA) plus your own organizational, physical, and administrative safeguards, not a single vendor feature. Redaction is one real technical safeguard that supports a HIPAA-aware architecture; it isn't the whole program. Contact [email protected] if you need to discuss a BAA.

Are documents stored after processing?

Extracted results are stored in Postgres. The original uploaded file is stored temporarily in Azure Blob during processing. Generated PDFs are served via a time-limited signed URL. Retention periods for parse results are configurable per account.

PII protection shouldn't require a separate pipeline.

One parameter handles detection and redaction end-to-end.