Why Vanilla LLMs Fail at HR Compliance (And How I Built a Hybrid Risk Checker in Next.js)
A few months ago, I started building a lightweight pre-send wording checker for small-business HR teams called RetaliationCheck. The idea was simple: most U.S. workplace retaliation lawsuits don't happen because a compa
A few months ago, I started building a lightweight pre-send wording checker for small-business HR teams called RetaliationCheck.
The idea was simple: most U.S. workplace retaliation lawsuits don't happen because a company is evilβthey happen because a stressed manager fires off a sloppy Slack message or write-up two weeks after an employee takes FMLA leave or files an HR complaint. When we looked at public EEOC resolutions for what retaliation settlements actually cost, administrative payouts routinely hovered around $40,000, and federal court cases easily crossed six figures.
My first prototype was what every dev builds in 2026: take the manager's draft email, wrap it in a long system prompt, send it to an LLM, and ask it to score the legal risk.
It failed miserably.
Here is why pure LLM prompts break down on compliance toolsβand the hybrid deterministic + LLM pattern that actually made it usable.
The 3 Ways Pure Prompts Failed
- Non-deterministic math. If you ask an LLM to check whether a 12-person layoff violates the EEOC's four-fifths (80%) adverse impact rule, it will confidently hallucinate the ratio about 15% of the timeβor round the wrong direction on borderline numbers.
- Temporal blind spots. In employment law, when you send a write-up matters as much as what you write. An email sent 18 days after an FMLA request carries totally different risk than the exact same email sent 11 months later. Pure text prompts constantly underweighted the calendar.
- Useless hedging. Without strict structural constraints, models default to "This may carry some risk; you should consult an employment attorney." Nobody pays for a tool that just tells them to hire a $600/hour lawyer.
The Fix: Deterministic Engines First, LLM Second
Instead of asking a model to do both math and copy-editing, I split the pipeline into two layers:
- Layer 1 (Pure TypeScript): Deterministic rules for dates, thresholds, and decision trees. Zero AI, 100% reproducible, unit-testable.
-
Layer 2 (Structured LLM Output): Only handles what LLMs are actually great atβspotting subjective/emotional phrasing (
"bad attitude","since your leave","stirring up drama") and rewriting it into boring, fact-only HR language.
Here is a simplified slice of how we score temporal proximity and decision-maker overlap in TypeScript before the LLM ever sees the draft:
export type ProtectedEvent =
| "fmla_leave"
| "ada_accommodation"
| "hr_complaint"
| "wage_inquiry"
| "pregnancy_pwfa";
export interface RiskInput {
daysSinceProtectedEvent: number;
hasPreEventDocumentation: boolean;
sameManagerAsComplaint: boolean;
actionType: "caution" | "written_warning" | "pip" | "termination";
}
export function computeBaselineRisk(input: RiskInput) {
let score = 0;
const flags: string[] = [];
// Temporal proximity window (under 90 days is high scrutiny)
if (input.daysSinceProtectedEvent <= 30) {
score += 40;
flags.push("High temporal proximity (<= 30 days since protected activity)");
} else if (input.daysSinceProtectedEvent <= 90) {
score += 25;
flags.push("Moderate temporal proximity (31-90 days)");
}
// Missing pre-complaint paper trail
if (!input.hasPreEventDocumentation) {
score += 25;
flags.push("No documented performance history prior to protected event");
}
// Decision-maker conflict
if (input.sameManagerAsComplaint) {
score += 20;
flags.push("Same manager involved in both complaint and discipline");
}
// Severity multiplier
if (input.actionType === "termination") score += 15;
if (input.actionType === "pip") score += 10;
return {
score: Math.min(score, 100),
tier: score >= 65 ? "HIGH" : score >= 35 ? "MODERATE" : "LOW",
flags,
};
}
Once Layer 1 computes the hard flags (HIGH, missing pre-event trail, same manager), we inject those exact facts into Layer 2 as read-only context. Now the LLM isn't guessing the legal severityβit's focused strictly on flagging risky sentences and producing a clean rewrite.
Turning Rules Into Standalone Free Utilities
One unexpected side effect of pulling the deterministic logic out of the LLM prompt: each rule module became a fast, zero-latency client-side tool on its own.
Instead of gating everything behind a login wall, I shipped the deterministic modules as standalone free calculators in Next.js App Router:
- A retaliation risk calculator for scoring the 90-day timing window before sending a PIP or warning.
- A caution vs. written warning decider so managers stop mislabeling formal discipline as a casual "caution."
- A WARN Act and adverse impact checker that runs exact four-fifths ratio math on layoff spreadsheets in the browser without uploading employee data to any server.
Building those as pure client-side TypeScript modules also solved a huge privacy objection: HR teams are rightfully paranoid about pasting employee names or layoff spreadsheets into random AI wrappers. When the math runs locally in the browser, there's zero PII hitting an API.
Main Takeaway for Indie Devs Building Vertical AI Tools
If you're building in a regulated or high-stakes niche (HR, finance, legal ops, healthcare admin), resist the urge to throw everything into one giant prompt.
Pull every date calculation, statutory threshold, and branching checklist out into plain TypeScript first. Use the LLM strictly as a language transformer on top of deterministic guardrails. Your outputs get 10x more consistent, your token bill drops, and you end up with genuinely useful micro-tools that users actually bookmark.
Happy to answer any questions about the Next.js setup, structured outputs, or building compliance tools as a solo dev!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.