Keeping the AI Revolution on the Rails with Shreya Rajpal of Guardrails AI
Summary
Guardrails AI is a runtime specification and correction layer between stochastic language models and deterministic software. Shreya Rajpal built it after finding that prompts—even those padded with instructions and exclamation marks—were “woefully inadequate” for guaranteeing usable outputs. Developers define correctness field by field; Guardrails validates the response, packages failures into targeted feedback, re-asks only for broken components, and merges the corrections.
The immediate wedge is making LLM output safe enough to become a software instruction rather than merely generated text. Rajpal’s credit-card example constrains extracted interest rates by type, format, and reasonable range; her text-to-SQL example executes queries in a sandbox, returns execution errors for self-correction, blocks private tables, and rejects operations such as DROP, UPDATE, or INSERT. The conclusion: domain expertise must become an executable correctness specification.
Better frontier models do not eliminate the infrastructure opportunity because cost, latency, portability, and rising product ambition keep reliability binding. Nathan Labenz observes that GPT-4 can perform Waymark’s core task zero-shot while GPT-3.5 Turbo is “20 times cheaper” but less dependable. Rajpal expects “great-performing models at different price points, with different latencies, from different providers,” making a model-independent validation layer more valuable as the supplier base expands.
Semantic validation broadens software testing beyond syntax, types, and executable code. Guardrails can decompose a summary sentence by sentence, match each claim to source passages, remove sentences below a developer-set similarity threshold, and filter redundant content. Rajpal’s preferred architecture ensembles rules, heuristics, narrow high-precision models, and LLM critics into something “greater than the sum of its parts”—a probabilistic defense, not a claim of certainty.
Agent reliability is a compounding-error problem whose solution requires validation at every decision and action. Labenz frames naïve multi-agent systems as “only as strong as the weakest link in the chain”; Rajpal agrees that agents need correctness specifications, but notes that autonomously generated goals make constraints harder to configure dynamically. Booking a flight illustrates the gap: understanding intent is increasingly tractable, while calendars, budgets, payments, logins, and two-factor authentication make grounded execution fragile.
The sharper safety disagreement is whether adoption waits for trust or outruns it. Rajpal warns that even technically perfect agents could face a “trust deficit” and argues that oversight must surface when humans are genuinely needed; Labenz counters that Guardrails may be “saving people from themselves,” because users will delegate after systems merely seem reliable. Fergal Reid frames the operating principle as “trust but verify,” and stresses that correctness is context-specific: profanity filtering may help factual generation but harm an authentic chatbot.
Security has to surround the model because training cannot cover the long tail of adversarial behavior. Rajpal recommends developers “sandwich the LLM API call” with input and output validation, limiting accepted interactions and checking prohibited behaviors after generation. The same framework supports re-asking, deterministic repair, filtering, exceptions, or a default no-op mode that returns the output while logging failures—letting each product encode its own tolerance for cost, latency, and error.
Deep dive
1. Reliability broke the moment LLM output entered production software
Rajpal began with her own prototypes: document-chat applications looked powerful, yet repeated testing showed that they could not reliably produce the intended experience. Unlike traditional machine learning, the application developer did not train the model and could not simply add domain data; the practical control surface was a prompt augmented with “a lot of verbiage” and perhaps “a lot of exclamation marks.”
Her diagnosis was categorical about the underlying mismatch: language models are “really potent and they’re really powerful,” but also “inherently very stochastic and very hard to control.” A product team may know exactly what a correct response looks like while lacking a systematic way to express, test, and enforce that knowledge.
Guardrails turns that knowledge into a specification. Developers decompose an expected output, validate its components independently, and choose how each failure should be handled; the framework therefore targets both the model’s output and the brittle interface where probabilistic generation meets conventional software.
Rajpal drew the design analogy from autonomous driving, where a deep-learning perception system feeds a more rule-based decision system. The engineering problem is not to pretend perception never fails, but to make “the interface between that stochastic system and that deterministic system” robust when it does.
2. Structured extraction exposes the simplest investable wedge
Rajpal’s prototype used her own Chase credit-card agreement. She wanted clean JSON containing key terms, while knowing in advance that an interest rate must be numeric, may include a percentage sign, and should fall within a reasonable range; a fee name should be concise enough to work as a displayed or downstream variable.
The model might extract the right concept yet return it inconsistently, making a later data sync unreliable. Guardrails lets the developer constrain each entity’s type, range, format, description, and relevance, replacing the vague instruction “give me JSON” with a schema against which every response can be checked.
This is less glamorous than open-ended reasoning, but commercially foundational: a generated answer becomes operational only when ordinary software can parse and trust its interface. Labenz later recognized the immediate convenience—developers can define the desired structure at a higher level instead of hand-coding XML-like examples and stripping away prefixes such as “I hope this was helpful.”
Early traction supported the breadth of the pain point: Labenz cited roughly 1,200 GitHub stars at recording time. The signal was not merely enthusiasm for another model wrapper; it was demand for a reusable contract between probabilistic models and applications.
3. Text-to-SQL shows correctness is domain knowledge made executable
In text-to-SQL, a user asks a natural-language question and expects a query that actually runs against a particular database. Guardrails creates a SQL sandbox, executes the generated query, captures the reasons it failed, and sends those errors back to the model so it can correct itself for that environment.
Executability is only the first layer. A developer can exclude private tables, restrict which tables customers may query, and reject operations such as DROP, UPDATE, or INSERT—constraints that express business permissions and security policy rather than SQL grammar alone.
Rajpal’s framing: every application owner has domain expertise about “what correctness means to me in this task” and how much a violation matters. A malformed query may be wholly useless and require correction; a softer quality failure may only need to be logged for later handling.
4. Semantic validators push testing beyond anything an assert statement could express
Labenz located the conceptual frontier between explicit software errors—syntax, missing variables, invalid types—and judgments such as whether an answer is reasonable, relevant, or logically coherent. Rajpal’s answer was not one universal evaluator, but an ensemble of rule-based checks, heuristics, conventional classifiers, and language models used as critics.
Her summarization example decomposes a seemingly indivisible text into sentences. Each sentence is similarity-matched to passages in the source, enabling fine-grained attribution; developers then set a threshold reflecting how much variation they accept and can remove sentences whose source similarity falls below it.
Concision becomes another independently testable property. Guardrails compares sentences within the generated summary and filters those too similar to one another, addressing redundancy without regenerating everything. The larger method is to break an ambiguous quality judgment into smaller, verifiable tasks.
Rajpal sees a second-order capability beyond generation: “you can really use these models as verification systems.” An LLM may judge another LLM’s work, while a smaller classifier may be preferable when latency, proprietary data, or precision matters. Later, Fergal Reid argued that greater evaluator diversity and ensembling can provide more guarantees and confidence.
5. Reliability economics survive even when GPT-4 follows instructions well
Labenz’s Waymark example made the price-performance trade-off concrete. A fine-tuned GPT-3 first performed its video-script task about a year and a half earlier, imperfectly; GPT-4 could now largely do it zero-shot, while GPT-3.5 Turbo was less reliable but roughly “20 times cheaper.”
That creates one value driver for Guardrails: move selected workloads to cheaper, faster, or open-source models while retaining an application-level reliability target. Rajpal had already heard from developers who liked both Guardrails and OpenAI but found the latter too expensive for what they were building.
Rajpal nevertheless said the more interesting aspect for her is the task being performed, not model substitution. Guardrails matters most where the LLM is used “not just as a text generator but as like a software instruction”—for example, an AI receptionist that must follow a workflow, respect availability, schedule correctly, and avoid requesting private information.
Creative products still carry hard constraints. A generated script may need to exclude profanity, competitors, or peer products even when originality is desirable; validation lets creativity remain unconstrained where useful while enforcing the requirements that make an output acceptable.
6. Targeted re-asking converts qualitative feedback into a correction loop
Rajpal first preserved an important limitation: human feedback remains a valid and often essential way to decide whether an output meets a user’s original criteria. Guardrails begins where some portion of that qualitative judgment can be codified into specific failures using rules, machine learning, or another LLM.
Once codified, failures become actionable context. Guardrails identifies the relevant broken fields, constructs a corrective prompt, requests only those pieces again, and merges them into the prior response; the user experiences one call even if the backend invokes the model multiple times.
This exploits a capability Rajpal considers genuinely new: models can “self-heal or self-correct themselves if you give them enough context.” The framework systematizes the human pattern of returning to ChatGPT, explaining why an answer failed, and asking for another attempt.
The boundary remains domain-dependent. “This text must be funny” is nearly impossible to score reliably, while medical or other high-stakes outputs may require human confirmation even after automated screening. Codification reduces supervision; it does not make every subjective or consequential decision automatable.
7. Agents compound errors faster than they compound capability
Labenz mapped Guardrails onto systems where one model plays several scaffolded roles—a planner, coder, retriever, or even every person in a simulated town. Because each step has some probability of failure, a naïve chain is “only as strong as the weakest link,” making validation the connective tissue between roles.
Rajpal agreed that agents need constraints and correctness specifications, but identified a structural gap: conventional applications have developers who define tasks and outputs, whereas agents may generate their own goals and execution plans. Humans therefore lack the fine-grained entry point needed to attach guarantees to each dynamically created action.
The target architecture would evaluate agents continuously without requiring a developer to pre-author every step. Rajpal called this “the key problem to solve” before these agents are employable beyond exciting demonstrations.
AutoPR, a community-built GitHub action, illustrated a constrained workflow: it converts an issue into a pull request, but generated files must exist and diffs must be valid for the repository. Those concrete invariants make the workflow amenable to runtime validation.
8. Grounded execution—not language understanding—is the near-term bottleneck
Labenz distinguished real-time copilots from delegated systems. Waymark is highly structured: users delegate scriptwriting and asset selection, then inspect a rendered video. Agents become more relevant when a user wants to say “go book me the flight” and expects the system to resolve every downstream dependency.
His work with executive-assistant company Athena exposed the split. Models could understand a client’s request, parse its meaning, and propose sensible follow-up questions, yet still failed at “hit the right buttons” execution involving web interfaces, checkout, payments, logins, or two-factor authentication.
Rajpal translated flight booking into grounded constraints: destination, schedule, budget, live availability, and user preferences. Validation must occur at every decision and action, not only on the final itinerary, because each step must remain grounded in those constraints.
9. Human trust may lag capability—or dangerously run ahead of it
Rajpal imported another lesson from self-driving: capability and adoption are separate questions. Even if agents became technically perfect, she said there would be a “trust deficit” around delegation; systems therefore need verification that exposes what they are doing and preserves control at each consequential step.
Labenz took the opposite behavioral bet. Rather than refusing delegation until guardrails exist, users may quickly conclude “yeah, it seems like it works” and discover only later how bad the downside can be; in that framing, Rajpal is “saving people from themselves.”
Labenz cited a finding he attributed to Harvard medical-school professor Zach Kahani: GPT-4 was better at evaluating text than generating it, encouraging self-critique workflows—but a nominally human-in-the-loop clinician can still become lazy or overly trusting as model quality rises.
Fergal Reid argued that humans will remain essential because correctness varies by context. Profanity filtering may be appropriate for factual generation but harmful for a chatbot whose authenticity depends on imitating someone who uses profanity. He also warned that constant “pay attention” alerts eventually lose force, while too little intervention invites complacency.
10. Security demands an input-and-output sandwich around the model
Labenz argued that prompt injection, adversarial users, manipulated webpages, and an emerging AI-search/SEO arms race will reveal vulnerabilities that benign testing misses. Model substitution adds another risk: a cheaply fine-tuned Llama does not necessarily provide the same operational behavior or safety as OpenAI or Anthropic systems.
Rajpal rejected the idea that training alone can close this gap. Stochastic models face a long tail of “exciting and weird ways” people will use them, and no dataset can cover every adversarial input; security properties therefore require more deterministic machinery around the model.
Her design pattern is to “sandwich the LLM API call” with input and output validation. Input gates can restrict interactions to supported categories or detect known injection patterns; output checks can catch forbidden behaviors even when the input filter misses the attack.
The objective is defense in depth, decomposed by application. Instead of asking one model to be universally safe, a team defines the acceptable domain and filters what lies outside it—multiple checkpoints analogous to production machine-learning systems that alternate learned components with deterministic or human validation.
11. Runtime controls complement moderation, evals, and model training
OpenAI’s moderation endpoint exemplifies one narrow validator: classify an output into a finite set of potentially problematic content categories, then let the developer choose the downstream action. Rajpal’s generalization is to make that pattern extensible to code, summaries, extracted structures, database queries, and application-specific criteria.
Failure handling reflects the product’s “pain tolerance.” High-stakes unusable output may trigger targeted re-asking; a bad summary sentence or profane passage may be filtered; a value may be repaired deterministically; another application may raise an exception.
Guardrails’ default no-op behavior still runs every validator but returns the original output unchanged, logging what failed. That gives teams observability before enforcement and creates evidence for deciding whether to revise prompts, models, thresholds, or runtime policy.
Rajpal viewed OpenAI Evals as a different, offline system for benchmarking tasks users care about—and admired its crowdsourced product loop. Anthropic’s Constitutional AI similarly acts through training, whereas her interest is configurable post-hoc control that can change without retraining whenever a product’s definition of correctness changes.
12. A configuration layer could become the portability standard for model proliferation
Guardrails’ RAIL specification—described as Reliable AI Markup Language—separates the output schema from the high-level task prompt. Developers express types, structure, and validation rules in markup; Guardrails then compiles that contract into the prompting strategy suited to a particular model.
The abstraction also absorbs model drift. A developer can retain one specification as an underlying model’s behavior changes; the framework can update how the contract is rendered into instructions, including model-specific techniques such as instruction tags.
Overhead is not one-directional. Re-asking adds latency, but Rajpal found that users whose applications genuinely require correctness are often willing to wait; structured constraints can also consume fewer tokens than verbose English instructions and reduce the engineering complexity of repeated prompt experimentation.
Labenz wondered whether OpenAI’s behavior would become the de facto standard because surrounding tools are built against the current leader. Rajpal still expects provider diversity—different prices, latencies, specializations, and open-source options—and sees interoperability pressure while standards and models co-evolve. Her broader hope is to automate taxes, travel booking, and other mundane work; her fear is displacement as AI makes knowledge workers substantially more efficient.