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.
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.
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.
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.”
- 01Send listing + whole PDF to one model call
- 02Model: “Mostly compliant; consider softening the wording”
- 03Misses the 12-month minimum lease buried on page 34
- 04No severity, no citation, nothing to audit
- 01Extractor → leaseTermMonths: 3, furnished: true
- 02Fair-housing → “No Section 8”: source-of-income violation (CA) · BLOCK
- 03Fair-housing → “young professionals”: possible familial-status preference · REVIEW
- 04CC&R checker → Art. 7.3, p. 34: minimum lease 12 months · BLOCK
- 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.
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.
price, leaseTermMonths, furnished, textThe submission, with its extracted fields and current state.
Property —governedBy→ HOALinks each listing to the community and its governing documents.
doc, article, page, text, ruleTypeA citable unit of a CC&R or title document. Findings must point to one.
rule, severity, confidence, evidenceWhat 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)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.
text → ListingFieldsStructured fields from the broker's paragraph. Small model; no tools.
PDF → Clause[]Splits CC&Rs and title docs into clauses with article and page, and tags rule types (lease, rental cap, pets, STR).
text → Finding[]Flags language that states a preference about protected classes or source of income, with the exact phrase as evidence.
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))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.
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?”
- 01Chunk the 60-page CC&R into fixed-size pieces
- 02Embed the question; take the 5 most similar chunks
- 03The clause says “leased for less than one year”: no “3-month”, no “rental”; it ranks 9th
- 04Model answers from 5 unrelated chunks: “no restriction found”
- 01At ingestion: parse into clauses with article, page, and ruleType
- 02Query: every Clause where ruleType = min_lease_term, not just the top k
- 03LLM reads Art. 7.3 → limit: 12 months, with the exact quote
- 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.
Top-k returns the most similar chunks. A restriction phrased differently is silently missed.
Filtering by ruleType returns every clause of that kind.
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.
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.
“…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.”
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.
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
])
}Evals decide what ships; caching decides what it costs
past listings + broker-of-record decisionsReal submissions labeled with the findings a human expert expected, including known violations.
recall on source_of_income, precision on petsScored per rule, not as one average. Missing a violation and raising a false alarm cost different things.
mini for extraction · larger model for clause readingExtraction and tagging run on a small model; only clause interpretation and fair-housing nuance use the larger one.
keyed by PDF hashAn 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.
Decisions I made, and what they cost
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.
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.
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.
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.
What changed, and what I'd do next
- 01Every listing gets a structured report with page-level citations, so reviewers check evidence instead of re-reading PDFs.
- 02Clear violations are blocked before publication; uncertain cases reach the broker of record with the evidence attached.
- 03Every state change and human decision is logged, so “why was this listing held?” has a precise answer.
- 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