KatInterview

Build an Agent Pipeline to Revise Contracts Against Rule Sets

Machine LearningModel answer
MediumModel answerMachine Learningllm-agentsmulti-step-reasoningedit-tracking

Last updated

Design a system that uses LLMs to automatically rewrite a contract so it satisfies dozens of compliance rules, handling overlaps, conflicts, verification, and cost.

You're building an automated compliance system. The input consists of a contract document and a set of dozens of compliance rules. Each rule specifies a requirement the contract must meet. Your task is to design an LLM-powered agent architecture that modifies the contract to satisfy all the rules and produces a compliant output.

Walk through your architecture: how you structure the processing pipeline, how you represent and coordinate edits when multiple rules target overlapping sections, how you validate that all rules are met, and the trade-offs in terms of API cost and response time.

What You Should Address

  • Work decomposition: How do you break the problem across LLM calls?
  • Edit representation: What format captures each proposed change and which rule triggered it?
  • Conflict handling: What happens when two rules affect the same clause in incompatible ways?
  • Validation: How do you confirm every rule is satisfied and no unintended edits were made?
  • Practical constraints: Latency, token cost, failure modes, and observability.

Clarifying Assumptions

Before diving in, consider asking:

  • What is the contract length relative to the model context window?
  • Can rules contradict each other, and is there a priority ordering?
  • Should the output include change tracking and justifications, or just the final text?
  • What latency and cost budget is acceptable per contract?
  • Is a human lawyer reviewing the result before it's finalized?
  • Must sections unaffected by any rule remain byte-for-byte identical?

Hints

Hint 1

Don't try to apply all rules in a single prompt—think about parallelism, attribution, and retry granularity.

Hint 2

Consider how you'll represent proposed edits so they can be merged, prioritized, or rejected without corrupting the document.

Hint 3

Verification is separate from generation: use a different prompt or model call to check whether each rule is satisfied in the final draft.