Skip to main content

Legal Tech: Protecting Privilege

How a legal technology provider secured AI-assisted drafting and research while preserving confidentiality.

Challenge

The platform supported:
  • Contract analysis and clause suggestions
  • Case law research summaries
  • Drafting and redlining assistance
Critical Requirements
  • Preserve attorney-client privilege and confidentiality
  • Isolate case context across firms and matters
  • Prevent leakage of confidential facts in outputs

Solution

KoreShield scanned prompts and outputs with strict policies and enforced per-matter isolation.
import { Koreshield } from 'koreshield-sdk';

const koreshield = new Koreshield({
  apiKey: process.env.KORESHIELD_API_KEY,
  sensitivity: 'high',
});

async function secureLegalAssist(userId: string, matterId: string, prompt: string) {
  const scan = await koreshield.scan({
    content: prompt,
    userId,
    metadata: { matterId, domain: 'legal' },
  });

  if (scan.threat_detected) {
    return { error: 'Blocked unsafe legal request' };
  }

  const draft = await generateLegalDraft(prompt);

  const outputScan = await koreshield.scan({
    content: draft,
    metadata: { matterId, output: true },
  });

  if (outputScan.threat_detected) {
    return { error: 'Output failed privilege checks' };
  }

  return { draft };
}

Matter Isolation Strategy

Every request included a matter identifier and tenant boundary:

Tenant Scoping

Firm and matter IDs enforced per request

RAG Partitioning

Retrieval limited to the matter workspace

Token Boundaries

Outputs limited to the scoped context

Privilege Controls

1

Matter Isolation

Prompts and retrieved docs scoped per matter - no cross-contamination
2

PII/Privilege Redaction

Removed sensitive entities from logs and audit trails
3

Audit Trails

Every prompt and response recorded for compliance and e-discovery
4

Human Review

High-risk responses queued for attorney approval before use

Architecture

Implementation Example

async function scanLegalInput(
  prompt: string,
  userId: string,
  matterId: string
) {
  // Scan for prompt injection and data exfiltration
  const scan = await koreshield.scan({
    content: prompt,
    userId,
    metadata: {
      matterId,
      domain: 'legal',
      sensitivity: 'privileged',
    },
  });

  if (scan.threat_detected) {
    await auditLog.create({
      userId,
      matterId,
      action: 'INPUT_BLOCKED',
      threat: scan.threat_type,
      confidence: scan.confidence,
    });

    throw new SecurityError(
      'Request contains potential security threat'
    );
  }

  return scan;
}

Review and Compliance Workflow

Flagged privileged entities before output:
  • Client names and identifiers
  • Opposing party information
  • Settlement amounts and terms
  • Attorney work product
  • Strategic legal analysis
Stored drafts with immutable audit metadata:
  • Document version history
  • Author and timestamp
  • Matter association
  • Review status
  • Approval workflow state
Periodic verification of matter access lists:
  • Quarterly access audits
  • Automated revocation on matter closure
  • Role-based permissions
  • Chinese wall enforcement

Results

Privilege Protection

Reduced risk of privileged data exposure across matters

Output Quality

Improved consistency of legal output quality

Compliance

Clear compliance posture for enterprise clients

Use Cases

Secure Clause Review
async function analyzeContract(
  contractText: string,
  matterId: string,
  userId: string
) {
  // Scan input contract for threats
  await scanLegalInput(contractText, userId, matterId);
  
  // Generate analysis with matter context
  const analysis = await ai.analyze({
    contract: contractText,
    context: await getMatterContext(matterId, userId),
    task: 'identify-risks',
  });
  
  // Scan output for privilege leakage
  await scanLegalOutput(analysis, matterId);
  
  return analysis;
}

Best Practices

Legal AI Security Principles
  1. Matter isolation is non-negotiable - Never mix context across matters
  2. Scan inputs and outputs - Threats can appear in prompts or generations
  3. Maintain audit trails - Essential for e-discovery and malpractice defense
  4. Review high-risk outputs - Human attorney oversight for sensitive matters
  5. Educate users - Attorneys must understand AI limitations and risks

Lessons Learned

Begin with strict policies and high sensitivity settings. Legal privilege violations can result in malpractice claims and ethical violations. It’s better to have false positives than miss a privilege leak.
Attorneys need training on:
  • What the AI can and cannot do
  • How to phrase requests safely
  • When to escalate to human review
  • Ethical obligations when using AI
Conduct monthly reviews of:
  • Blocked requests (false positives?)
  • Access patterns (unusual activity?)
  • Output quality (hallucinations?)
  • Compliance metrics (audit ready?)

Security

Core security features

Configuration

Policy configuration

Monitoring

Alerts and dashboards

Build docs developers (and LLMs) love