Back to case studiesCase study · System design

Listing & Lease Compliance Review

How I designed a system that reads free-form listings and legal PDFs, checks them against fair-housing law and HOA rules, and blocks or escalates anything risky, without letting an LLM make the final call.

Domain
Real estate brokerage & property management
My role
System design, architecture, implementation
Input
Listing text + title docs + HOA CC&Rs (PDF)
Output
Structured compliance report + publish / hold / block decision
00 · Overview

Four layers, each with one job

Every listing passes through the same four layers. The LLM does reading and judgment inside layer 2; layers 1, 3 and 4 are there to make that judgment safe, accountable, and affordable.

Broker submits listing text + PDFs
1 · Control
What exists and what is allowed to happen
Read the guide
Listing ontologyListing state machineAudit log
2 · Execution
Single-responsibility agents with typed contracts
Read the guide
Intake extractorDocument parserFair-housing checkerCC&R checkerReport writer
3 · Risk
Confidence and severity decide who decides
Read the guide
Risk scorerRouterBroker-of-record review queue
4 · Quality & cost
Measured, versioned, and affordable at volume
Read the guide
Golden dataset + per-rule evalsModel cascadePer-document cache
Published
Held for broker of record
Blocked, with fixes
01 · Context

The problem behind “just check if it's compliant”

Brokers submit a listing as a paragraph of text plus attachments. Before it goes live, someone has to confirm two things: the wording doesn't violate fair-housing law, and the terms don't break the community's CC&Rs. Both answers are buried in unstructured text.

Extract
Turn free-form listing text into structured fields: property type, rent or price, lease term, furnished, pets, occupancy, description.
Read the documents
Parse title documents and CC&Rs into clauses, each with its document, article, and page number.
Check
Fair-housing language (protected classes, source of income in California) and CC&R restrictions (minimum lease term, rental caps, short-term rental bans, pets).
Decide
Publish clean listings, block clear violations with reasons, and hold uncertain ones for the broker of record.
Explain
A structured report where every finding cites the exact clause and page it relies on.

The non-functional requirements shaped the design more than the functional ones: no listing may be published without passing checks or a human approval; every decision must be reproducible and auditable; and the same HOA document shouldn't be paid for twice when ten listings share it.

02 · Walkthrough

One listing, two designs

A sample submission (illustrative), with a 60-page CC&R PDF attached:

“Charming 2BR condo in Irvine, perfect for young professionals. Available as a 3-month furnished rental. No Section 8.”
One prompt: “Is this compliant?”
A plausible paragraph, no evidence
  1. 01Send listing + whole PDF to one model call
  2. 02Model: “Mostly compliant; consider softening the wording”
  3. 03Misses the 12-month minimum lease buried on page 34
  4. 04No severity, no citation, nothing to audit
Four-layer design
Three findings, each with a source
  1. 01Extractor → leaseTermMonths: 3, furnished: true
  2. 02Fair-housing → “No Section 8”: source-of-income violation (CA) · BLOCK
  3. 03Fair-housing → “young professionals”: possible familial-status preference · REVIEW
  4. 04CC&R checker → Art. 7.3, p. 34: minimum lease 12 months · BLOCK
  5. 05State → BLOCKED; report sent to broker with fixes

The deterministic numbers (3 months vs. 12) are compared in code. The LLM's job is to find the clause and read the language, not to do the arithmetic or make the final decision.

03 · Layer 1 — Control

An ontology and a state machine own the process

Agents never decide what happens next. The ontology defines the objects they work on; the state machine defines which transitions are legal.

Listing
price, leaseTermMonths, furnished, text

The submission, with its extracted fields and current state.

Property → HOA
Property —governedBy→ HOA

Links each listing to the community and its governing documents.

Clause
doc, article, page, text, ruleType

A citable unit of a CC&R or title document. Findings must point to one.

Finding → Review
rule, severity, confidence, evidence

What a checker found, and the human decision on it if one was needed.

const listingFlow = {
  SUBMITTED:     { EXTRACTED: "CHECKING" },
  CHECKING:      { CLEAN: "AUTO_APPROVED", RISK: "NEEDS_REVIEW", VIOLATION: "BLOCKED" },
  AUTO_APPROVED: { PUBLISH: "PUBLISHED" },
  NEEDS_REVIEW:  { APPROVED: "PUBLISHED", REJECTED: "BLOCKED" },
  BLOCKED:       { REVISED: "SUBMITTED" },   // broker edits and resubmits
} as const

// Guard: PUBLISHED requires zero open BLOCK findings, whatever path led here.
guards.PUBLISHED = (l: Listing) => l.findings.every((f) => f.severity !== "block" || f.resolved)
Listing lifecycle. Publishing is only reachable through a passing check or a human approval.
04 · Layer 2 — Execution

Five agents, one job each

Each agent has a short prompt, only the tools it needs, and a schema for its output. A malformed output fails at the boundary instead of three steps later.

Intake extractor
text → ListingFields

Structured fields from the broker's paragraph. Small model; no tools.

Document parser
PDF → Clause[]

Splits CC&Rs and title docs into clauses with article and page, and tags rule types (lease, rental cap, pets, STR).

Fair-housing checker
text → Finding[]

Flags language that states a preference about protected classes or source of income, with the exact phrase as evidence.

CC&R checker
ListingFields + Clause[] → Finding[]

Retrieves relevant clauses, extracts the limit (e.g. 12 months), and lets code compare it to the listing.

const Finding = z.object({
  rule: z.enum(["fair_housing", "source_of_income", "min_lease_term", "rental_cap", "str_ban", "pets"]),
  severity: z.enum(["block", "review", "info"]),
  confidence: z.number().min(0).max(1),
  evidence: z.object({
    listingPhrase: z.string().optional(),
    clauseId: z.string().optional(),     // must exist in the Clause table
    page: z.number().int().optional(),
  }),
  explanation: z.string(),
})

// Citation check in code: the quoted clause text must actually appear on that page.
const verified = findings.filter((f) => !f.evidence.clauseId || clauseMatches(f.evidence, clauses))
Every finding must carry evidence. A finding without a verifiable citation is rejected, not reported.

The fifth agent, the report writer, turns verified findings into a broker-facing report with suggested rewrites. It has no ability to change a finding's severity or the listing's state.

05 · Design decision

Why not plain RAG?

The obvious design is to chunk the CC&Rs, embed them, and retrieve the top few chunks for each listing. I used retrieval, but not that way: documents are parsed into clause objects once, and every check queries those objects by rule type.

“Does this listing's 3-month lease break the HOA's rules?”
Classic RAG
Top-k by similarity, read at query time
  1. 01Chunk the 60-page CC&R into fixed-size pieces
  2. 02Embed the question; take the 5 most similar chunks
  3. 03The clause says “leased for less than one year”: no “3-month”, no “rental”; it ranks 9th
  4. 04Model answers from 5 unrelated chunks: “no restriction found”
Clause objects
Structured once, queried every time
  1. 01At ingestion: parse into clauses with article, page, and ruleType
  2. 02Query: every Clause where ruleType = min_lease_term, not just the top k
  3. 03LLM reads Art. 7.3 → limit: 12 months, with the exact quote
  4. 04Code verifies the quote on p. 34 and compares 3 < 12

Illustrative example, real failure mode: compliance needs every applicable clause, and similarity search ranks results. It doesn't guarantee completeness.

Completeness

Top-k returns the most similar chunks. A restriction phrased differently is silently missed.

Filtering by ruleType returns every clause of that kind.

Citations

Fixed-size chunks split clauses in half and lose article and page numbers.

Clause boundaries and pages are kept at parse time, and every quote is verified.

Consistency

Change the embedding model or chunk size and the same listing can get a different verdict.

The clause index only changes when the document changes. Same inputs, same result.

Exceptions

“…except units owned by the Declarant” is re-interpreted by the model on every query.

Interpreted once at ingestion, reviewable, and stored as a field on the clause.

Vector search still has a role: pgvector runs as a fallback to catch clauses the tagger may have mislabeled, and its hits go to review rather than being trusted. Fair-housing checks need no retrieval at all; they read the listing text directly. For the broader shift away from classic RAG, see the guide “Why Everyone Built RAG, and Why Many Teams Are Moving On.”

06 · Layer 3 — Risk

Severity and confidence decide who decides

Prompting the model to “be careful” doesn't make it careful. Instead, each finding gets a severity from the rule type and a confidence from checkable signals, and the router acts on both.

Block, high confidence
Clear violation with verified evidence (a numeric CC&R limit, an explicit “No Section 8”). Listing is blocked; broker gets the reason and a fix.
Block, low confidence
Possible violation but the citation is weak or the clause is ambiguous. Goes to the broker of record; never auto-blocked or auto-approved.
Review
Judgment calls such as “perfect for young professionals.” Held for a human with the phrase and the guidance side by side.
No findings
Auto-approved and published; a sample is still spot-checked weekly and added to the eval set.
function confidence(f: Finding, ctx: Ctx): number {
  return weighted([
    citationVerified(f, ctx.clauses),       // quoted text found on the cited page
    agreement(f, ctx.secondPass),           // independent re-check agrees
    deterministicMatch(f, ctx.listing),     // e.g. 3 < 12 computed in code
    ruleHasPrecedent(f, ctx.goldenSet),     // similar labeled cases exist
  ])
}
Confidence comes from signals that can be checked, not from the model rating itself.
07 · Layer 4 — Quality & cost

Evals decide what ships; caching decides what it costs

Golden dataset
past listings + broker-of-record decisions

Real submissions labeled with the findings a human expert expected, including known violations.

Per-rule evals
recall on source_of_income, precision on pets

Scored per rule, not as one average. Missing a violation and raising a false alarm cost different things.

Model cascade
mini for extraction · larger model for clause reading

Extraction and tagging run on a small model; only clause interpretation and fair-housing nuance use the larger one.

Per-document cache
keyed by PDF hash

An HOA's CC&Rs are parsed once and reused by every listing in that community, keyed by file hash, not by similarity.

Recall matters most for the block rules: a missed violation is far more expensive than a listing held for review. Thresholds were set conservatively and are only loosened when the eval set shows the checker is reliable for that rule.

08 · Trade-offs

Decisions I made, and what they cost

Who compares the numbers

Rejected: let the LLM judge whether a 3-month lease violates the CC&Rs.

Chosen: the LLM extracts “12 months” with a citation; code does the comparison. Arithmetic is never a judgment call.

Whole PDF vs. clause index

Rejected: paste the full CC&R into every prompt. Expensive, and long-context recall drops on page 34 of 60.

Chosen: parse once into tagged clauses; retrieve by rule type; verify the quote on the cited page.

Warn vs. block

Rejected: only warn the broker and let them publish anyway.

Chosen: hard block for verified violations. Slower for brokers on bad listings, which is the point.

One agent vs. five

Rejected: one agent that reads, checks, and writes. A wrong finding couldn't be traced to a step.

Chosen: five agents with contracts. More moving parts, but each can be evaluated and fixed alone.

09 · Results & next steps

What changed, and what I'd do next

  1. 01Every listing gets a structured report with page-level citations, so reviewers check evidence instead of re-reading PDFs.
  2. 02Clear violations are blocked before publication; uncertain cases reach the broker of record with the evidence attached.
  3. 03Every state change and human decision is logged, so “why was this listing held?” has a precise answer.
  4. 04Next: feed reviewer decisions back into the golden set automatically, and add jurisdiction-specific rule packs beyond California.

Have a compliance-heavy workflow?

Documents in, decisions out, with a human in control of the risky ones. I can help you scope and build it.

Talk through your use case