KatInterview

Build a Playbook-Driven Contract Review Pipeline with Citations

System DesignModel answer
MediumModel answerSystem Designsystem-designllm-agentstraceability

Last updated

Design an asynchronous service that checks contracts against versioned rule sets, cites exact text spans, proposes edits, assigns a risk tier, and lets reviewers override results.

Problem

A company's legal department wants software that reviews incoming contracts and policy documents against its internal review guidelines (a "playbook"). For each uploaded document, the service should:

  • assign an overall risk tier: Approved, Acceptable with Deviations, or High Risk / Escalate;
  • propose precise edits (redlines) for clauses that deviate from the playbook;
  • tie every finding to the rule that produced it and to the exact passage of the document it concerns;
  • combine the opinions of several domain specialists (for example IP, liability, data privacy) and settle cases where they disagree;
  • let human reviewers accept, reject, or change any finding or the final tier, and keep those corrections.

Requirements

Functional

  1. Ingestion: accept PDF and DOCX and keep exact character offsets plus visual coordinates for every piece of text.
  2. Rules: support both deterministic checks (regex, clause present or absent, date limits, numeric limits) and judgment-based checks done by a model (such as indemnity exposure or whether a non-compete is reasonable).
  3. Traceability: each finding, score and suggested edit points to an immutable rule ID and version and to an exact span in the source.
  4. Specialists: run domain specialists in parallel and reconcile conflicting findings.
  5. Human review: reviewers can override results; all corrections are stored for audit and for later model evaluation.

Non-functional

  • 10,000 documents per day, peaking at 1,200 per hour.
  • Average length about 25 pages (roughly 16k tokens), maximum 150 pages.
  • P95 latency under 30 seconds for typical documents, delivered via polling or webhook.
  • At least 99.5% of citations must be correct. Invented quotes or broken offsets are unacceptable.

What to cover

  1. Schemas for Rule, DocumentSpan, Finding and EvaluationReport, plus the main API calls.
  2. The pipeline from parsing and offset generation, through deterministic pre-checks and specialist model runs, to conflict resolution and tier assignment.
  3. How you keep results reproducible when rules change over time.
  4. How you reconcile specialists that disagree (a priority matrix, an adjudicator model, or both).
  5. How you would measure quality offline: span accuracy, rule adherence, and edit quality.

Hints

Hint 1

Do the capacity math first. About 0.33 documents per second is small; the real challenge is correctness, so figure out where token cost and the 150-page tail actually bite.

Hint 2

Never let a model emit character offsets. Give it span IDs in the prompt and have a validator check any quoted text against the parser's canonical text before a finding is published.

Hint 3

Make rules and playbooks immutable and content-hashed, pin the version at submission time, and store raw model outputs plus a manifest of parser, model and prompt versions.

Hint 4

For conflicts, order the resolution steps from most to least trustworthy: verified deterministic facts, rule owner, higher severity, then an adjudicator model with human escalation. Compute the final tier with plain code.