[BidClub_]
The Cognitive Revolution · · 94 分钟

与 Guardrails AI 的 Shreya Rajpal 一起让 AI 革命不脱轨

Nathan LabenzEoghan McCabeFergal Reid

YouTube
TL;DR
  • Guardrails AI 是位于概率性语言模型与确定性软件之间的运行时规范与纠错层。 Shreya Rajpal 发现,即便提示词塞满指令和感叹号,也“远远不足以”保证输出可用,于是搭建了 Guardrails。开发者逐字段定义正确性;Guardrails 校验响应,将失败封装成定向反馈,只针对出错组件重新提问,再合并修正结果。

  • 眼下最直接的切入口,是让 LLM 输出足够安全,能够成为软件指令,而不只是生成文本。 Rajpal 以信用卡为例,按类型、格式和合理区间约束抽取出的利率;在 text-to-SQL 案例中,系统在沙箱执行查询,将执行错误返回给模型自我修正,屏蔽私有表,并拒绝 DROP、UPDATE 或 INSERT 等操作。结论是:领域知识必须转化为可执行的正确性规范。

  • 前沿模型变强,并不会消除基础设施机会,因为成本、延迟、可移植性和不断上升的产品目标,仍会让可靠性成为约束。 Nathan Labenz 观察到,GPT-4 可以零样本完成 Waymark 的核心任务,而“便宜20倍”的 GPT-3.5 Turbo 可靠性较低。Rajpal 预计,未来会出现“不同价位、不同延迟、来自不同供应商的高性能模型”,供应商越多,与模型无关的验证层就越有价值。

  • 语义验证把软件测试从语法、类型和可执行代码,扩展到更广的层面。 Guardrails 可以逐句拆解摘要,将每个论断与来源段落匹配,删除低于开发者设定相似度阈值的句子,并过滤冗余内容。Rajpal 偏好的架构,是将规则、启发式方法、窄领域高精度模型和 LLM 评审器组合起来,形成“整体大于部分之和”的系统——这是概率性防线,而非确定性承诺。

  • 智能体的可靠性是一个误差累积问题,解决方案是在每个决策和动作上都进行验证。 Labenz 将朴素的多智能体系统描述为“链条中最弱的一环有多强,系统就有多强”;Rajpal 认同智能体需要正确性规范,但指出,目标由系统自主生成后,动态配置约束会更加困难。订机票体现了这一差距:理解意图越来越可行,但日历、预算、支付、登录和双重认证等环节,让有依据的执行仍然脆弱。

  • 更尖锐的安全分歧在于:产品采用会等到信任建立,还是会跑在信任前面。 Rajpal 警告,即便技术上完美的智能体也可能面临“信任赤字”,并认为系统必须在真正需要人类介入时及时暴露这一点;Labenz 则反驳说,Guardrails 可能是在“拯救人们免于自作自受”,因为用户只要觉得系统足够可靠,就会开始委托。Fergal Reid 将运行原则概括为“信任但验证”,并强调正确性取决于场景:过滤脏话可能有助于事实生成,却可能损害一个追求真实感的聊天机器人。

  • 安全必须包围模型,因为训练无法覆盖对抗行为的长尾。 Rajpal 建议开发者在“LLM API 调用前后夹上验证层”,限制可接受的交互,并在生成后检查被禁止的行为。同一框架还支持重新提问、确定性修复、过滤、抛出异常,或采用默认空操作模式:原样返回输出,同时记录失败,让每个产品自行编码对成本、延迟和错误的容忍度。

摘要 · 为研究而整理的核心内容

1. LLM 输出进入生产软件的那一刻,可靠性就开始崩溃

  • Rajpal 从自己的原型讲起:文档聊天应用看起来很强大,但反复测试后发现,它们无法稳定地产生预期体验。与传统机器学习不同,应用开发者既没有训练模型,也不能简单地加入领域数据;实际可控的界面,只剩下提示词,外加“大量文字说明”,或许还有“大量感叹号”。

  • 她对底层错配的判断是明确的:语言模型“真的很有能力,也真的很强大”,但同时“天生具有很强的随机性,非常难以控制”。产品团队可能清楚知道正确响应应该是什么样,却缺少系统化表达、测试和执行这套知识的方法。

  • Guardrails 把这些知识转化为规范。开发者拆解预期输出,分别校验各个组件,并决定每种失败应如何处理;因此,这套框架既瞄准模型输出,也瞄准概率性生成与传统软件交汇处那条脆弱的接口。

  • Rajpal 从自动驾驶中借鉴了设计类比:深度学习感知系统向更偏规则驱动的决策系统提供输入。工程问题不是假装感知系统永远不会失败,而是要在失败发生时,让“这个随机系统与那个确定性系统之间的接口”保持稳健。

2. 结构化抽取暴露出最简单、最具投资价值的切入口

  • Rajpal 的原型使用了自己的 Chase 信用卡协议。她希望得到包含关键条款的干净 JSON,同时提前知道利率必须是数字,可以带百分号,并应落在合理区间内;费用名称则应足够简洁,能够作为展示字段或下游变量使用。

  • 模型可能抽取出了正确概念,却以不一致的形式返回,导致后续数据同步不可靠。Guardrails 允许开发者约束每个实体的类型、范围、格式、描述和相关性,用一套可检查的 schema,替代“给我 JSON”这种模糊指令。

  • 这不如开放式推理光鲜,却是商业化的基础:生成答案只有在普通软件能够解析并信任其接口时,才真正具备操作价值。Labenz 后来意识到,这一工具的即时便利在于,开发者可以在更高层定义目标结构,无需手写类似 XML 的示例,也不用再剥离“I hope this was helpful”之类的前缀。

  • 早期 traction 证明了这一痛点的广泛性:Labenz 提到,录制时项目在 GitHub 上约有1,200颗 star。这一信号不只是市场对又一个模型封装器的兴趣,也反映出市场需要一份能在概率性模型与应用之间复用的契约。

3. Text-to-SQL 说明,正确性就是被执行化的领域知识

  • 在 text-to-SQL 中,用户用自然语言提问,希望得到一条能在特定数据库上实际运行的查询。Guardrails 创建 SQL 沙箱,执行生成的查询,捕获失败原因,再把错误返回给模型,让模型针对这一环境自行修正。

  • 可执行只是第一层。开发者可以排除私有表,限制客户可查询的表,并拒绝 DROP、UPDATE 或 INSERT 等操作;这些约束表达的是业务权限和安全政策,而不只是 SQL 语法。

  • Rajpal 的框架是:每个应用负责人都拥有关于“在这个任务里,对我而言什么才算正确”的领域知识,也知道违反规则的代价有多大。一条格式错误的查询可能完全不可用,必须修正;较轻的质量问题则可能只需记录下来,留待后续处理。

4. 语义验证把测试推进到 assert 语句无法表达的领域

  • Labenz 将概念边界划在显式的软件错误——语法错误、变量缺失、类型无效——与“答案是否合理、相关、逻辑自洽”等判断之间。Rajpal 的答案不是设计一个通用评估器,而是组合规则检查、启发式方法、传统分类器和作为评审器的语言模型。

  • 她以摘要为例,将一段看似不可拆分的文本分解成句子。每个句子都与来源中的段落进行相似度匹配,从而实现细粒度归因;开发者再设定一个阈值,体现自己接受多大程度的变化,并可以删除与来源相似度低于阈值的句子。

  • 简洁性也可以成为独立测试的属性。Guardrails 比较生成摘要中的句子,过滤彼此过于相似的内容,在无需重新生成全文的情况下处理重复问题。更大的方法论是:把含混的质量判断拆成更小、可验证的任务。

  • Rajpal 认为,这套能力还带来了生成之外的二阶价值:“你确实可以把这些模型用作验证系统。”一个 LLM 可以评判另一个 LLM 的工作;而在延迟、专有数据或精度更重要时,小型分类器可能更合适。之后,Fergal Reid 认为,更高的评估器多样性和集成方法,能够提供更多保障和信心。

5. 即便 GPT-4 更擅长遵循指令,可靠性经济学仍然成立

  • Labenz 的 Waymark 案例具体呈现了价格与性能的权衡。大约1年半前,一套微调后的 GPT-3 首次完成 Waymark 的视频脚本任务,表现并不完美;如今 GPT-4 基本可以零样本完成,而 GPT-3.5 Turbo 的可靠性较低,但价格大约“便宜20倍”。

  • 这为 Guardrails 创造了一个价值驱动因素:在保留应用层可靠性目标的同时,把部分工作负载迁移到更便宜、更快或开源的模型上。Rajpal 已经听到一些开发者反馈:他们同时喜欢 Guardrails 和 OpenAI,但认为后者对于正在构建的产品来说过于昂贵。

  • 不过,Rajpal 说,对她而言更有意思的是模型正在执行什么任务,而不是模型替换本身。Guardrails 最有价值的场景,是 LLM 被使用时“不是仅仅作为文本生成器,而是像一条软件指令”——例如 AI 接待员必须遵循工作流、尊重可用时间、正确安排日程,并避免索取私密信息。

  • 创意产品同样有硬约束。生成脚本可能需要排除脏话、竞争对手或同类产品,即便原创性本身值得鼓励;验证机制让创意在有价值的地方保持不受限,同时执行那些决定输出能否被接受的要求。

6. 定向重新提问,把定性反馈转化为纠错闭环

  • Rajpal 首先保留了一个重要限制:人类反馈仍然是判断输出是否符合用户原始标准的有效、且往往不可或缺的方法。Guardrails 的起点,是将其中一部分定性判断通过规则、机器学习或另一个 LLM,编码成具体失败项。

  • 一旦被编码,失败就会变成可执行的上下文。Guardrails 找出相关的出错字段,构造纠正提示词,只要求模型重新生成这些部分,再将结果合并进原响应;用户感知到的仍是一次调用,即便后端实际调用了模型多次。

  • 这利用了 Rajpal 认为真正新出现的一项能力:只要提供足够上下文,模型就能“自我修复或自我纠正”。这套框架把人类反复回到 ChatGPT、解释答案为何失败并要求再次尝试的行为系统化了。

  • 边界取决于领域。“这段文字必须有趣”几乎无法可靠评分,而医疗或其他高风险输出,即便经过自动筛查,也可能仍需人工确认。编码可以减少监督,但不会让每个主观或高后果决策都变得可自动化。

7. 智能体的错误累积速度快于能力累积速度

  • Labenz 将 Guardrails 映射到这样一类系统:一个模型承担多个由脚手架组织起来的角色——规划器、编码器、检索器,甚至模拟城镇中的每一个人。由于每一步都有一定失败概率,朴素的链式系统“链条中最弱的一环有多强,系统就有多强”,验证于是成为各角色之间的连接组织。

  • Rajpal 认同智能体需要约束和正确性规范,但指出了一个结构性缺口:传统应用由开发者定义任务和输出,而智能体可能自行生成目标和执行计划。于是,人类缺少把保障机制附着到每个动态生成动作上的细粒度入口。

  • 理想架构应当持续评估智能体,而不要求开发者预先授权每一步。Rajpal 称这是“需要解决的关键问题”,否则这些智能体很难从令人兴奋的演示走向可雇佣、可工作的系统。

  • 社区构建的 GitHub Action AutoPR 展示了一个受约束的工作流:它将 issue 转换成 pull request,但生成的文件必须存在,diff 也必须符合仓库要求。这些明确不变量,让整个流程适合进行运行时验证。

8. 近期瓶颈在有依据的执行,而不是语言理解

  • Labenz 区分了实时副驾驶与委托型系统。Waymark 的流程高度结构化:用户委托脚本写作和素材选择,随后检查渲染后的视频。当用户希望直接说“帮我订一张机票”,并期待系统解决所有下游依赖时,智能体才变得更重要。

  • 他与高管助理公司 Athena 的合作暴露出两者的分野。模型能够理解客户请求、解析含义并提出合理的追问,却仍然无法可靠地“点对按钮”,而这涉及网页界面、结账、支付、登录或双重认证。

  • Rajpal 将订机票转化为一组有依据的约束:目的地、时间安排、预算、实时可用性和用户偏好。验证必须发生在每个决策和动作上,而不只是最终行程上,因为每一步都必须持续符合这些约束。

9. 人类信任可能落后于能力,也可能危险地跑在能力前面

  • Rajpal 从自动驾驶中引入了另一条经验:能力与采用是两个不同问题。她说,即便智能体在技术上变得完美,用户在委托任务时仍可能存在“信任赤字”;因此,系统需要验证机制,展示自己正在做什么,并在每个重要步骤保留控制权。

  • Labenz 押注于相反的行为路径。用户未必会等到护栏建立后才拒绝委托,而可能很快得出“对,看来它能用”的结论,直到后来才发现下行风险有多严重;在这一框架下,Rajpal 是在“拯救人们免于自作自受”。

  • Labenz 引用了他归因于哈佛医学院教授 Zach Kahani 的一项发现:GPT-4 在评估文本方面优于生成文本,这推动了自我批评工作流;但即便名义上有人工参与的临床医生,也可能随着模型质量提升而变得懒惰或过度信任。

  • Fergal Reid 认为,人类仍将不可或缺,因为正确性随场景变化。过滤脏话可能适合事实生成,却可能伤害一个需要模仿脏话使用者、以保持真实感的聊天机器人。他还警告,持续弹出“注意”提醒最终会失去作用,而干预过少则会助长自满。

10. 安全要求在模型输入和输出两端形成夹层

  • Labenz 认为,提示词注入、对抗性用户、被操纵的网页,以及正在形成的 AI 搜索与 SEO 军备竞赛,会暴露出良性测试无法发现的漏洞。模型替换还会带来另一重风险:廉价微调的 Llama 并不一定具备与 OpenAI 或 Anthropic 系统一致的运行行为或安全性。

  • Rajpal 不认同仅靠训练就能弥合这一差距。随机性模型将面对人们使用它们时“令人兴奋且古怪的各种方式”,任何数据集都无法覆盖每一种对抗性输入;因此,安全属性需要模型周围更具确定性的机制来保障。

  • 她的设计模式是在“LLM API 调用前后夹上验证层”。输入闸门可以将交互限制在受支持的类别内,或检测已知的注入模式;输出检查则可以在输入过滤器漏掉攻击时,捕捉被禁止的行为。

  • 目标是按应用拆解纵深防御。团队不再要求一个模型普遍安全,而是定义可接受的领域,过滤超出边界的内容——这相当于设置多个检查点,类似生产级机器学习系统在学习组件之间交替加入确定性或人工验证。

11. 运行时控制补足内容审核、评估和模型训练

  • OpenAI 的 moderation endpoint 是一种窄范围验证器:将输出归类到一组有限的潜在问题内容类别中,再由开发者决定下游动作。Rajpal 的扩展思路,是将这一模式推广到代码、摘要、结构化抽取、数据库查询和应用特定标准。

  • 失败处理取决于产品的“痛苦承受度”。高风险且不可用的输出可能触发定向重新提问;糟糕的摘要句子或包含脏话的段落可以被过滤;某个值可以通过确定性方式修复;另一个应用则可能直接抛出异常。

  • Guardrails 的默认空操作模式仍会运行每个验证器,但原样返回输出,并记录失败项。这让团队在执行规则前先获得可观测性,也为后续决定是否调整提示词、模型、阈值或运行时政策积累证据。

  • Rajpal 认为,OpenAI Evals 是另一套用于离线基准测试的系统,评估用户真正关心的任务;她也认可其众包式产品闭环。Anthropic 的 Constitutional AI 同样通过训练发挥作用,而她关注的是可配置的事后控制:当产品对正确性的定义发生变化时,无需重新训练即可调整。

12. 配置层可能成为模型大规模扩张时代的可移植标准

  • Guardrails 的 RAIL 规范,即 Reliable AI Markup Language,将输出 schema 与高层任务提示词分离。开发者用标记语言表达类型、结构和验证规则;Guardrails 再将这份契约编译成适合特定模型的提示策略。

  • 这套抽象也能吸收模型漂移。底层模型行为变化时,开发者可以保留同一份规范;框架则更新契约被渲染成指令的方式,包括 instruction tags 等模型特定技术。

  • 开销并非单向增加。重新提问会增加延迟,但 Rajpal 发现,真正需要正确性的应用用户通常愿意等待;结构化约束消耗的 token 也可能少于冗长的英文指令,并降低反复试验提示词的工程复杂度。

  • Labenz 怀疑,OpenAI 的行为是否会成为事实标准,因为周边工具都围绕当前领先者构建。Rajpal 仍然预计供应商将保持多元:不同价格、不同延迟、不同专长,以及开源选项都会存在;在标准与模型共同演化的过程中,互操作性压力也会持续存在。她更广泛的希望,是让税务、旅行预订和其他琐碎工作自动化;她的担忧,则是 AI 大幅提升知识工作者效率后带来的岗位替代。

Shreya Rajpal

It’s kind of insane to see the amount of activity and excitement around the space. There are people training and fine-tuning deep learning models who weren’t even in the space a few months ago, and that’s really awesome.

I’ve had people say, “I really like Guardrails. I really like OpenAI, but it’s just too expensive for what I’m trying to build. Can you make this work with an open-source model?” I do think we’re going to see a lot of that proliferation: great-performing models at different price points, with different latencies, from different providers.

Nathan Labenz

Today my guest is Shreya Rajpal, a former machine learning engineer at Apple and founding engineer at Predibase, who is now best known as the creator of Guardrails AI, a new Python library that allows developers to add a layer of output validation and correction to their code.

Anyone who has spent time building AI-powered products over the last 2 years will attest that validation, and even more so reliability, are key challenges. LLMs simply don’t always follow instructions, and sometimes go entirely off the rails. Better models have helped tremendously. It’s true that GPT-4 can follow instructions far more reliably than earlier models, and Claude v1.3 is also very impressive. But with this elevated capability also comes expanded developer ambition, and so it seems that, for the foreseeable future, the problem of LLM reliability will remain both critical and ubiquitous.

Shreya’s work tackles this problem in many ways and at multiple levels. Super practically, Guardrails can ensure a reliable interface between language models and more traditional deterministic software systems. Does the language model return data with the right type and format? Did the model choose a value from the list of allowable values that we provided? These are very familiar questions for developers, and they’re still powered in Guardrails by traditional code.

At the same time—and for me, this is clearly the more novel, exciting, mind-bending, and potentially risky use case—frameworks like Guardrails allow developers to ask and answer entirely new kinds of questions: assessments of things like the quality of a summary or translation, or whether a given piece of text contains redundancies, inconsistencies, or gaps in logic. These are the sorts of things that, until recently, developers simply had no way to validate.

Thus, for product and engineering teams around the world, Guardrails is both a solution to a very practical problem at hand and an introduction, or bridge, to an emerging paradigm of AI-first software development. That paradigm goes well beyond the Copilot-style autocomplete or even chat interfaces that we’ve recently seen, and begins to use AI functions not just as development tools, but as components of the production technology stack itself.

Talking to Shreya really reinforced for me just how early we are in LLMs’ impact on the software industry. The core AI capabilities needed to transform software, as far as I can tell, mostly already exist. What remains is the work of reimagining not only how software is built, but how it functions now that intelligence can be baked in at any point.

Personally, I believe that this paradigm shift could ultimately unlock bigger productivity gains and more user value than the current generation of tools that increase developer speed but don’t yet attempt to change the kind of software that they’re building. At the same time, this is something to be approached with real care and caution. The delegation of AI output validation to other AI models is not a step to be taken lightly or taken for granted.

Shreya Rajpal, welcome to The Cognitive Revolution.

Shreya Rajpal

I’m really excited to be here. Thanks for inviting me.

Nathan Labenz

My pleasure. This is the first time that I’ve invited a guest basically as soon as I got off the call recording a previous episode. Matt Welsh, CEO of Fixie.ai, mentioned your new project, Guardrails AI, and I was immediately like, “Okay, I have to learn everything I can about this.” I’m really excited to dive into it with you.

I guess let’s start with what made you say, a couple of months ago, “I need to build a system to help people keep their language models on the rails”?

Shreya Rajpal

I was really solving my own pain points and my own problems. At the end of last year, I had been doing some tinkering on my own, building some applications. A lot of what you were seeing on Twitter was about chatting over proprietary documents, and I was building that. I realized that this was pretty cool and that I could see the potential, but even as a developer testing it out, I could tell that it didn’t reliably get me the desired experience—the experience that I wanted to achieve.

These language models are really potent and powerful, but they’re also inherently very stochastic and hard to control. The other thing that makes this very interesting is that, unlike traditional machine learning, you haven’t really trained the model as a developer. You can’t just throw more data at it that could work really well for your use case.

Separately, the only knob you really have as a developer is, “Here’s this prompt.” If you want it to do something or not do something, the way developers typically deal with that is by adding a lot of verbiage to the prompt, and maybe a lot of exclamation marks, to make it listen to you. That just seems woefully inadequate.

Guardrails is this idea of a specification framework where, as a developer, you know what the right output for an LLM looks like. You’re able to decompose and deconstruct that output, and individually validate and verify each component. If any of those components or quality criteria fail, Guardrails gives you a set of tools to address that in a very extensible manner.

I was building this and thinking, “I know what responses I want a user to be able to get from this thing that I’m building. How do I ensure that I’m always able to do that for a wide variety of scenarios?” That was some of the inspiration.

I also spent some years working on autonomous systems and self-driving. It’s a similar problem there, where you have a really powerful deep-learning-based perception model that often feeds into a more rule-based decision-making system. How do you ensure that the interface between that stochastic system and that deterministic system is robust and not brittle whenever the perception system doesn’t do as well?

The idea was inspired by some techniques you would see there, but built for language models and built in a very extensible way so that it’s not domain-specific.

Nathan Labenz

As much as possible, I love to get super concrete on these things. This is clearly a pain point that a lot of people have. The project has gone on its own little rocket-ship ride of GitHub stars, with 1,200 as of last check at the time of this recording, but a lot of people listening could use a more concrete example.

What kind of thing are you looking for, how is it failing, and can you tell us a couple of those examples? How does Guardrails come in and save the day in those instances?

Speaker 1

Absolutely. My favorite prototype example is that I have this Chase credit-card agreement, which was my own credit-card agreement, and I want to extract the key terms from it and get a nice JSON object out of it.

As a user, I know that if I’m extracting something like an interest rate, it must always be a number. It might have a percentage sign in it, and there’s a reasonable range for what that number can be. If I’m extracting the name of a specific fee and I want that name to be presented somewhere, I know that the name should be very concise. It should be like a variable.

One common failure point is that if I want to extract this information and then add it to some downstream data sync, it’s hard to do that reliably and consistently from an LLM, because an LLM doesn’t behave reproducibly.

In this structured-data-extraction setting, I could enforce constraints on what I want each extracted entity to look like. The interest rate must be a number and must be within a reasonable range. There must be a description with each interest rate, and the description might need to be a certain length or relevant to whatever entity it comes along with.

All those constraints are what I want to impose on this JSON structure. That was a use case I was prototyping. Since then, I’ve added a lot of examples to the documentation, but one of my favorite ones is text-to-SQL.

Text-to-SQL is a wildly different domain, but many of the same ideas apply. You want correctness from any generated SQL query. The idea is that, as a user, you want to be able to ask natural-language queries over your data and get a SQL query that you can execute.

You need to be able to define the constraints you want to impose on that SQL query. It must actually work for the database or environment where you want to execute it. You may not want to return results from specific tables, or some tables might be private. If you’re a customer, you may never be able to query those tables, so you can filter them out.

You can add constraints such as only supporting specific SQL CRUD operations. If there are DROP operations, or perhaps UPDATE or INSERT operations, you may want to filter those out. As you’re setting up this text-to-SQL task, you can add all of those constraints.

Guardrails takes your database schema and sets up a SQL sandbox. Any SQL query that is generated is executed in that sandbox to make sure it’s executable. If it isn’t, you take all of the errors explaining why the SQL query failed to execute, wrap those errors into something, send them back to the large language model, and have it correct itself to get something that actually works for your specific database.

You can add other constraints and restrictions on top of that, such as filtering out specific tables or operations. The idea is that there’s a question or task you’re asking this large language model to solve, but as a developer, you have domain expertise about what correctness means for that task and how much you care about correctness.

If it’s incorrect, is the query totally useless to you? Or, if it’s incorrect, do you just want to know about it and handle it post hoc? Guardrails takes that idea and allows you to implement it as a developer.

Nathan Labenz

It’s fascinating. One of the things I want to explore most in this conversation is the seeming spectrum, or dimension, that we’re opening up. On one end, there are explicit errors—the errors we’re used to as developers in code. That could start with a syntax error and go up to more meaningful errors that can still be found through traditional software messages, such as “This variable doesn’t exist.”

Then you have a whole domain of correctness that code has never really accessed before. What are you trying to do? Does this appear to be a reasonable approach or output? That’s a much more semantic, or, dare I say, intelligent point of view.

I find myself a little confused or lost in that space, and I see that you’re covering it in an interesting mix of ways in the library and in the validators. There’s a mix of values there. Maybe walk us through how you think about that, along with some examples of different validators that sit in different parts of that space.

Shreya Rajpal

I think that was one of the very exciting things about the library as I was building it out. The general framework works even outside of things that you can verify with an assert statement. It’s extensible as a framework, where you can have a mix of large language models, rule-based heuristics, programmatic checking, and traditional machine-learning models, such as high-precision classifiers.

You can ensemble all of these techniques together to get something greater than the sum of its parts—something much more robust and reliable compared with just using a pure large language model.

As an example, I recently added a bunch of Guardrails for summarization. If you’re summarizing multiple documents and generating an aggregated summary from them, there are a bunch of requirements you may have to ensure that the summary is accurate, concise, and not redundant.

Guardrails thinks about this general problem of correctness, when assert statements aren’t sufficient, by breaking it down into smaller ML tasks or smaller verifiable heuristics, and trying to get an aggregate assessment.

In the case of summarization, if you want to figure out whether the summary is faithful to the original source text, you can look at each sentence in the summary and do similarity matching based on which parts or passages of the source text it’s most similar to. That allows you to do finer-grained attribution and figure out where the sentence is generally coming from.

You can also assign thresholds. As a developer, you can do some experimentation to figure out how varied you want these sentences to be from the original source text, set a threshold, and then filter out any sentence that falls below that threshold in terms of similarity score.

This is a way of thinking about text outputs that may seem like a single unit. It breaks them down into smaller chunks and independently tries to verify them.

Another technique for summarization is to make sure the summary is concise and contains no redundant information. Within the generated summary, you can make sure that each sentence is diverse enough from the other sentences. If that’s not the case, you can filter out sentences that are too similar to each other.

The cool thing about LLMs is that we’re looking at many of the first-order benefits, where you can use them to do a bunch of insane tasks. But I think the second-order benefit is that you can really use these models as verification systems and critique themselves.

You can use a large language model within a validator to verify and validate whether whatever you’re getting is correct. Or, depending on your access to data and latency requirements, you can use a smaller machine-learning model that does this for you.

The philosophy behind Guardrails is to bring together a bunch of different verification strategies and add guarantees around problems that have traditionally been harder to verify.

Nathan Labenz

That’s really interesting. I’m mapping this onto my own use cases in real time. I’m wearing my Waymark swag today. Waymark is in the video-creation space, and we have a multimodal problem. We ultimately take in some minimal information about a business, ask the user to tell us what they want to create, and then provide a ready-to-watch video.

We do that with an ensemble of different models working together, but the core one is the language model that writes the script and gives direction for what the visual assets should look like.

We’ve come so far in a year. It was just a year and a half ago that we got the very first fine-tuned GPT-3 model to do the task at all. It wasn’t good, but it would at least respect the nature of the inputs and outputs. Today, GPT-4 can basically do it zero-shot and respect the outputs. GPT-3.5 Turbo can do it, though not reliably, and it’s about 20 times cheaper.

I’m interested in what you see the value drivers being for this sort of thing. To some degree, maybe there’s no other way to do it, but GPT-4 is pretty reliable at this point. People might want to do it for cost savings, latency, or a lot of other reasons.

Cost savings and latency are benefits I could see. If I could move to a slightly less reliable model but still know that my stuff is going to render correctly for our users, that would be valuable. What are you seeing in terms of the value drivers from your community?

Shreya Rajpal

I think there are 2 aspects. Cost and latency—being able to use open-source models or cheaper models with the same level of reliability—are one aspect.

The more interesting aspect for me is the task that you’re truly using the model for. With Waymark, there are a lot of use cases where you’re using these models as writing assistants or to help you. One product I enjoy using is Notion AI Assistant. You give it a little bit of a draft, and it helps you shape up an outline.

For those use cases, the creativity of a large language model is actually very good, and it’s a desirable trade-off. But there’s another whole space of use cases that rely on the world model ingrained in these large language models, and use them as software abstractions to do more general-purpose reasoning.

One example is using an LLM as an AI receptionist. If you’re a small-business owner, instead of needing to hire a receptionist, you can use a large language model. Whenever you get calls, it figures out scheduling, who’s available, and so on.

That’s a powerful capability of the model, but creativity is perhaps not as desirable there. You want it to stick to a desired workflow. You want to make sure that it doesn’t ask for private information if a customer is calling, for example.

Guardrails is most useful in those situations, where you’re using the LLM not just as a text generator, but as a software instruction system. When you’re using it in that capacity, reliability becomes most useful.

Over the weekend, I shared something that a community contributor had built using Guardrails. It was a GitHub Action called AutoPR. AutoPR takes a GitHub issue and automatically creates a pull request for your codebase.

That’s one of those use cases with a bunch of really strict constraints. The files must exist, and the generated code diffs must be valid for those files. Those constraints are hard to enforce without having a validation framework such as Guardrails on top of it.

For a lot of those use cases, creativity isn’t as valuable. You want more reliability. It’s still such a powerful use case for these models that we would be underutilizing their capabilities if we didn’t build software like that.

Even with many creative use cases, I’ve found that there are still a bunch of constraints people implicitly have. Right now, the way to handle those constraints is through prompt tuning or prompt iteration.

Being able to encode these constraints and have a validation step run automatically is useful. You might not want any profanity in generated scripts, or, if you’re creating video content for a brand, you might not want to mention peer products or competitors. Those constraints are useful even with free-form text.

Nathan Labenz

It sounds like you’re most excited about something that couldn’t be achieved in traditional code. I’m still trying to find that line. Maybe there’s just a lot of overlap, and there’s probably some truth to that.

I’m thinking about AutoPR. It’s cool and super technical, but those responses could presumably be validated by existing libraries. The Git package itself probably has some way to say, “You haven’t got this together, so this isn’t going to work.”

I think that’s what many people are naively doing: implementing this stuff on a case-by-case basis. At Waymark, there is no standard. Nobody else has our video standard. We define and own it, so it was up to us to figure out how to represent that in text and what validation comes back from it.

If you were advising us when we were a little earlier, how would you think about what points of validation we ought to handle through Guardrails? Should we think about structure? Should we think about whether the copy satisfies the user’s prompt? There’s probably a lot of room in between. Those stake out the most rigid versus the most semantic desires or requirements from the model.

It seems like you’re more interested in the semantic side, but there’s also this fundamental interface with computing, where it gets very syntactic as opposed to semantic.

Shreya Rajpal

I want to preface this by saying that generating something, getting feedback from the end user about whether it’s good or meets the original criteria, and doing a more qualitative assessment is a very valid way of doing things.

For a lot of domains, getting human feedback and input is essential before you can really think that an output is correct and valid for whatever use case you have.

In the Guardrails world, there’s an idea that some of that human feedback can be done by a combination of traditional machine learning, heuristics, and perhaps more large language models in the loop.

If you can take some of that qualitative criteria and codify it into something more specific, you’re then able to generate specific failure messages that help the model correct its output.

I don’t know as much about Waymark, but it might help reduce the amount of back-and-forth you have with your end customer. You can take some of their constraints, run them programmatically, and, if the output is wrong, automatically create new prompts that tell the large language model why the previous outputs were incorrect and get it to correct itself.

This is one of the new capabilities we have with large language models: the ability to get them to self-heal or self-correct if you give them enough context.

That’s where Guardrails is most useful. Under the hood, it’s good at figuring out the relevant context, packaging it up, automatically creating a new prompt, getting a new response from the large language model, and merging that new response with the old response.

It’s very efficient. It only asks about the things that are wrong, rather than sending your whole previous output again. That merged result is your corrected, validated response.

That’s the world where Guardrails is most useful, but it’s also very domain-specific. There are domains where any text that’s generated must be funny. That’s next to impossible to validate. I can’t imagine writing a validator that functions as a scoring system for humor. That’s very hard to do, so you need a human expert.

There are other domains with very high stakes and a high cost of getting something wrong. Even if you can do some prescoring, actual human confirmation that the output is correct is essential before you do another iteration with the large language model.

There are domains where this re-asking strategy doesn’t work. But I do think the idea of taking what correctness means, or what an aligned output means, in your use case and trying to codify some of that is useful.

It helps with prompting the large language model, because it allows Guardrails to construct prompts that are more effective at getting what you want. It also allows for post hoc validation and a loop where you can systematically and programmatically handle failures as they arise.

That might involve re-asking or filtering incorrect output. It’s a powerful framework for requiring less human supervision and taking away the pain of going into ChatGPT, writing, “This doesn’t work for this reason,” and trying to write something else.

Nathan Labenz

Maybe it’s because we all have agents on the brain, but as I’m listening to you describe that, I’m going to the agent moment we’re in. When you dig into these agent systems, it’s usually a multi-agent system in many cases.

It might be the same language model playing different roles. We’re seeing examples of a simulated town where GPT-4 plays all the people, or a research agent where there’s a planner, a coder, and a retriever that all work together. They have their own prompts and are scaffolded together.

Of course, these things fail a lot, because there’s some probability of being wrong at any given point in the chain. In the naive implementation, you’re only as strong as the weakest link in the chain.

In a sense, what I’m learning is that the Guardrails paradigm is connective tissue between the different roles in a multi-agent system. I should probably accelerate how quickly I think these agents are going to start working.

Shreya Rajpal

Agents are very exciting. I’ve been thinking about them a lot and trying to understand how to make them more effective and reliable.

The interesting thing about agents versus how Guardrails works is that Guardrails solves the problem of adding constraints to an output so that it works for your use case. It gives developers a lot of agency to think about the specific problems they’re solving and what correctness means to them.

By contrast, many of the goals and tasks of agent frameworks are configured autonomously by a large language model itself. You’re in an interesting setting where the involvement of a human or developer—the ability to enter an agent framework and add guarantees—is usually not available at a fine-grained level.

With the agent frameworks that exist today, you typically don’t have access to the fine-grained level of task execution or goal setting, because you’re not the person configuring the agents themselves.

There’s a gap between how agents operate today and what humans would ideally like to have. If you want to employ a bunch of agents to do research for you, you want to be able to say, “This is the set of allowable things you can look at.” But you also want that configured dynamically based on where the agents are operating.

Constraints and correctness specifications are essential. They’re the only way to think about how to assess what these large language models are doing. You can stream them and evaluate each step to make sure they’re not going off the rails, but how do you do that dynamically when you’re not the person creating the agents or setting their goals?

That’s the key problem to solve. It’s a problem we don’t need to solve before these agents are employable or before we can truly use them outside of seeing how exciting they are.

For Waymark specifically, where there are constraints and a finite scope for what you want the large language model to do, have you looked at some of these agents and thought about what part of Waymark could be aided by agents?

Nathan Labenz

It’s probably not such a great fit for the Waymark product experience, because we have a lot of structure.

I think of these things as different modes—I’m still working out this framework. I talked about it with Matt Welsh, and that’s part of what led him to mention your project.

In terms of how we interact with AI systems, there seems to be a real-time Copilot mode, where you’re doing things as a human and the system is there to guide or shepherd you. Then there are situations where you’re ultimately delegating more because you don’t want to do the task yourself.

You don’t want to be the person in the driver’s seat, or the entity in the driver’s seat. You want to put the AI in the driver’s seat, let it do the work, and then look at its work when it’s done—or have some other way to circle that back into your life and workflows.

Right now, those workflows are largely done with integrations of various kinds. They could be code, no-code, Zapier, or something else. With Waymark, it’s a guided experience where you’re delegating the task of writing a script, choosing all the assets for your video, and so on. Then you watch the output.

There’s so much structure that it doesn’t feel like we need an agent to come in and mix things up too much. I do see an agent as the bridge between these 2 modes.

In ChatGPT Plus today, I can use a plug-in to look for flights, but I might want to tell the system, “Go book me a flight for this date, subject to my preferences,” and have it figure out all the downstream details.

This is also very relevant to me because I’m working with a company called Athena, which is in the executive-assistant space. They have these kinds of tasks all the time, where a human today is responsible for executing a lot of web tasks for a client.

There are different aspects of the cognitive work. One is understanding what’s going on—translating the client’s language, understanding what a request means, and asking the right follow-up questions. The other part is actually being able to hit the right buttons to make it happen.

Ideally, we delegate that whole thing. In our testing, along with everybody else, we’ve found that AI may be able to understand the request, parse it effectively, ask the right follow-up questions, suggest good follow-up questions, and demonstrate a robust understanding of what the human wants.

But we’re still falling down on how to hit the right buttons. God forbid you have to make a payment or log into something. Two-factor authentication still works as a deterrent to AI login, at least for the time being.

Shreya Rajpal

That’s been my experience as well. There’s an interesting wedge where agents can be useful, but for that wedge to succeed, you need this notion of grounding.

You need to figure out, “Here’s how the agent understands what I’m saying,” but at each step of the execution, you need validation.

The question of, “Book me a flight,” is interesting, because it’s based on my schedule, my budget, and where I’m trying to go. That translates into constraints grounded in my calendar, where I’m trying to go, and what flights are available.

Validation at each decision the large language model makes, and each action it takes, becomes more important for these systems to succeed.

Having worked a little in the self-driving world, part of the question is whether they’re able to do it, and part of it is whether a human can trust them. Even if these agents were perfect, there would be a trust deficit around how much people are comfortable delegating.

To build that trust, you need a verification system that makes sure that, at each step, you’re able to maintain control and oversight over how the agents execute.

Those frameworks are essential before we see adoption outside of demo use cases.

Nathan Labenz

It’s funny that you say that. I would take the other side of the bet when it comes to human behavior. If I understand you correctly, you’re saying that people won’t want to trust these systems unless there are good Guardrails in place.

I think of you as saving people from themselves, because people are going to be much quicker to say, “It seems like it works. Why not go ahead? What’s the worst that could happen?” We may find out, especially in a future world, that the worst could be quite bad.

I just recorded an episode with Zach Kahani, a medical-school professor at Harvard who wrote the book The AI Revolution in Medicine. This is exactly the kind of system he’s trying to figure out how to implement into clinical practice.

For now, of course, the human is in the loop. That’s the official recommendation. But it’s easy to get lazy and overly trusting, especially when the models are getting so good.

It’s fascinating that you can get better performance just by pointing the model at itself. One of his big findings was that GPT-4 is better at evaluating text than it is at generating text, and he’s starting to develop self-critique systems on the fly in the context of clinical exploration.

Fergal Reid

That’s part of what the Guardrails validation system is based on. It’s almost “trust but verify.” You get GPT to generate something, perhaps have a separate step that evaluates it, and add an additional layer of security.

Ideally, the more diverse evaluators you have, the more guarantees you get. Ensembling is a technique I’m pretty bullish on in this space, because it’s what will give us confidence.

The medical-AI assistant space is fascinating because it reminds me of self-driving. With autonomous vehicles that are out there today, such as Tesla’s Full Self-Driving, the idea is that you’re still supposed to be very alert. You’re not supposed to take your hands off the wheel.

There’s an expectation that a human should always be aware and present, but it’s easy for humans to get lazy. One of the things I’m excited about is good interface design, so that we can get human involvement when it’s most needed and not constantly notify people to “pay attention, pay attention,” because that eventually ceases to have an effect.

It’s about finding the balance between when human involvement is necessary and when we can offload some of the work programmatically or through code. Figuring out that balance, and the interface for surfacing the division of responsibilities, is very exciting.

Nathan Labenz

I don’t have a Tesla either, but a neighbor of mine does and has the Full Self-Driving package. Knowing that I’m as obsessed with AI as I am, he was gracious enough to take me for a ride.

First of all, it works much better than people commonly realize. I got into the car in front of my house, he put the destination on the screen, and hit the drive button. The car drove. There wasn’t much fuss between entering the destination and riding.

When you talk about the reminders, that’s something they’ve put a lot of engineering into as well. There are three progressions. First, there’s a visual indicator that you haven’t done anything with the wheel in a while. Some versions also have a camera that watches you from the rearview mirror.

Then it goes to a sound, and after that it gives you a warning that it’s going to pull over if you don’t keep your eyes on the road. They’re pretty far along in that. It was a remarkable experience because it’s a delicate balance, and it’s so easy to tune out.

Eventually, they can pull over. They can also kick you out of the program if you pull over too many times. My neighbor said that if you’re truly sleeping at the wheel, they’ll retract your access to Full Self-Driving.

It’s a fine balance because people can start to tune these things out. How many warnings do we tune out? It’s crazy.

The next big thing that comes to mind is the developer asking, “What’s right for me?” The pattern quickly becomes, “Why can’t an AI just do that?”

I start to think about whether there’s a version of this that’s a plug-in. You’ve created a specification, and I’m trying to envision what it will be like to use a computer a year from now, as the tooling and plumbing mature.

One possibility is a chat interface that lets you access the world and delegate tasks to little agents that go do things and report back. It seems like a GPT-4 central process could use the Guardrails specification, or something similar, to insulate itself from problems as it delegates tasks.

Do you see that as realistic? Do you have a point of view about how the computing experience might evolve in light of that?

Fergal Reid

That’s a very good question. It could go in a bunch of directions, but my core belief is that humans will remain essential in the loop. It will be very hard to automate all of this away.

One reason is that correctness means very different things to different people and in different contexts. A common example is profanity filtering. Most people can agree that if you’re generating facts, you should make sure they don’t contain profanity.

But I’ve also talked to people building chatbots for specific audiences where authenticity is essential. If the chatbot is trying to imitate, or be in the likeness of, someone who uses profanity, filtering out that profanity is actually detrimental to the user experience they’re building.

It’s very hard to figure out what those constraints are on a global level. Domain experts and developers need to be involved to figure out what they’re building, how they’re grounding it for users, and what the desired experience is.

Those inputs will continue to be important. There needs to be a way to configure those inputs, criteria, or the experience that a user or developer wants. Offloading this entirely to the model or to a provider will be hard to achieve because of that constraint.

In terms of what the programming or developer experience could look like, one hypothetical direction is to start thinking configuration-first. There could be a configuration system that allows you to tune the outputs you want to see from these LLMs.

Even if the underlying machine-learning model stays the same, you could configure how that model is validated and corrected, and how its outputs are post-processed. When people work with large language models, it’s not just text; it’s also this configuration that they pass in every time.

This is a pattern that I think will be particularly important in engineering. The prompt isn’t sufficient by itself, and choosing the LLM and temperature isn’t sufficient by itself. It’s a configuration framework for how you want the output to be and how you want the input to be processed or formatted.

Nathan Labenz

Security also jumps out to me as a major driver. As I think about where I would use this, GPT-4 is running pretty well and giving me the format I want. It certainly has errors, but it very rarely goes totally off the rails.

There are vectors that are still completely undeveloped and seem likely to come online and cause a lot of problems. Having an SLA or guarantee layer—a validation layer—seems very smart in light of prompt injection.

As users become more sophisticated and adversarial in their attempts, you gain a lot by having something like this implemented ahead of time. We’ve also seen interesting things in Bing, where a site owner—or perhaps a user—can change what the model sees.

We haven’t begun to see what SEO professionals are going to do in the AI-search era. The battle between search and SEO may look pale in comparison to what happens when you can try to trick a language model at runtime with whatever content you want.

Then there’s model risk. As impressive as GPT-4 is, my general strategy right now is to use it for everything, get the quality to an acceptable level, and then think about reducing cost or latency opportunistically as necessary.

Eventually people will say, “I heard Alpaca was just as good,” and try to drop that in instead. Then you’re in a world where you have no idea what’s going on. OpenAI and Anthropic have a certain SLA, and I think a huge misconception is that the SLA is an inherent property of language models.

It isn’t. Those companies have worked very hard to get to the level they’ve reached. You can’t take for granted that a bootlegged Llama fine-tuned on whatever data is going to be as safe or friendly to users.

All of this is just starting to emerge from the mist. How much did that motivate you? Do you see other things like that, and what do you make of all this emergent security that you’re helping people get in front of?

Shreya Rajpal

The risk of working with these models, especially prompt injection, is important. When Bing Chat was released, we saw how easy it was to manipulate these models in specific ways.

I think about this by decomposing the problem. I don’t think this is a problem that will be solved by machine learning alone. A lot of what OpenAI has managed to achieve is built on responsible scaling laws. As you add data and scale the models, you start to see emergent properties.

But, based on my experience working in machine learning, these are fundamentally stochastic systems. It’s very hard to add guarantees from the model itself. You can’t have data points for all the different exciting and weird ways that people are going to use these models.

As a consequence, it’s very hard to add validation at the model level. Security becomes essential because it isn’t something you can leave up to a stochastic system. You need more determinism around it.

My way of thinking about it is to break it down this way: the model is stochastic, so what can we do around the model to add watertight guarantees?

For prompt injection, I’m interested in both the input and output sides. You can sandwich the LLM API call with input validation and output validation to create multiple layers of security that make sure the model isn’t behaving in ways you don’t want it to.

On the output side, if there are behaviors you don’t want the large language model to exhibit, you can perform secondary checks through output validation. If you know the patterns of prompt injection that people tend to follow, you can look for those patterns in input validation.

You can almost gatekeep the queries and interactions users are able to have, limiting them to the set of things you support. The solution is to decompose the overall security problem into specific, domain-specific applications.

For each domain, think about the end goal you want your users to have, and then add constraints to filter out everything outside of that goal.

I would be very surprised if we had end-to-end machine-learning systems. There’s a reason we don’t. You generally have one machine-learning subcomponent, then a checkpoint with either a human or a more deterministic component verifying or validating its output, followed by another downstream component that may use machine learning.

Decomposing the system and adding different layers of security on either end of the language model is the pattern most people use when they try to productionize these systems. Defense in depth is going to become very important.

Nathan Labenz

Another version of this is models talking directly to other models in vector form. That seems like it’s going to become a huge trend.

We had the authors of BLIP-2 on the show a while back. I think of that as an emblematic foreshadowing of what’s to come. They were able to take a frozen vision model and a frozen language model, and quickly train a connector model that converts the encoding of an image into something in the language-embedding space.

That allows you to have a dialogue with the language model about the image. I see so many examples of even simple linear maps from one space to another, where people are bridging different encoded, latent, or embedding spaces.

That’s going to be a huge trend that brings much better performance to many systems. Why would you go through a natural-language bottleneck if you have a much richer representation of an image, a medical scan, or a sound?

If you have the sound of a bird in an audio file, you’re not going to project it down into language over the long term and say, “The sound of a bird is heard,” before feeding that into the language model. You’re going to figure out how to represent it in the language model’s space in a way that is truly unspeakable.

I see a lot of force going in that direction, but the obvious worry is that you’ve opened yourself up to who knows what. The space of possibility is so vast that it’s untestable and incomprehensible on the input side.

What can be done about that? Again, it seems like the answer is to start validating your outputs. That’s really important, and it’s only going to become more important.

People may be underestimating the extent to which they can create a system today that behaves predictably, while the world underneath it changes in ways that expose vulnerabilities over time.

Software has always worked that way to some extent. We’ve seen Windows patches released long after launch. But this seems different.

Shreya Rajpal

More sensory input from more sensors leads to better performance if you’re able to include it. That goes back to the idea of grounding that I mentioned earlier.

If you have a machine-learning system that projects something into a particular space, how do you make sure that the projection is correct? If you have grounding, where another sensory input is also projected into that space, you can use it as a self-correction or self-verification system.

At Drive.ai, where I worked, we saw that using only lidar was different from using cameras as additional inputs. When you have cameras in addition to lidar, you have a better understanding of the state the car is in and are able to make better decisions overall.

I think it’s a positive thing because it allows us to enforce Guardrails across multiple dimensions. It helps us figure out where things might break down and add checks.

I’m excited to see a world where we can have all these vectors in the same space and a lot of interoperability between them.

Nathan Labenz

You’re describing a validation step based on the coherence of the semantic interpretation of different input signals. I’m trying to think of an example I’ve seen in the wild. I guess you’re pointing to self-driving cars as one example.

I want to throw a few other safety-control paradigms at you and have you react to them—not necessarily in a better-or-worse way. Comparing and contrasting these approaches with what you’re building may help clarify which use cases your project is best suited for.

Most people listening will be familiar with OpenAI’s moderation endpoint. You can take an output, run it against the moderation endpoint, and receive a flag indicating whether it falls into one of a finite number of problematic content types. Then you can decide what to do with it.

That sounds pretty simple. Where does that approach fall short?

Shreya Rajpal

I think it’s great, but it’s very finite in scope. If you took something like that and expanded it to any use case you wanted to verify or validate—anything that was programmatically verifiable or verifiable with a machine-learning model—you could flag specific things within the output that might be problematic.

You could also configure how you want invalid outputs to be handled. That’s how I think about Guardrails.

Moderation, specifically profanity filtering, is one validator among many in the library. You take an LLM output and give it to the profanity-filtering validator. It tells you whether there is profanity in the output, and, depending on how you configure it, it can also correct it.

For example, it could generate the text without profanity, or filter out the sentences that contain profanity. You can take that pattern and apply it across many other use cases.

If generated code is incorrect or non-executable, you can do the same thing for code. If summaries generated from source text are incorrect or invalid, you can do it for summaries. If you’ve extracted structured data and specific parts of it are incorrect, you can apply the same paradigm.

It takes the moderation endpoint pattern and makes it a general, accessible tool that you can use in practice.

Nathan Labenz

What do you see people doing most often to fix things when validation fails? One option is to return an error. Another is to rerun the whole call and hope for a better result the second time. You’re also getting more granular, perhaps fixing only part of the output or removing the profanity.

How would you advise people to think about which option they should take when there’s a problem, and what do you see people actually doing today in the community?

Shreya Rajpal

That’s hard to answer because I can’t tell people what their pain tolerance is for their applications. Fundamentally, there are cases where an LLM output that fails validation is of no use. You either want it corrected or filtered out; you can’t use it in an intermediate state.

Re-asking is valuable. It allows you to treat the process as a single API call from the user’s perspective, even if the backend makes multiple calls to the large language model. You either get a corrected output or you’re told that the result is incorrect and can’t be handled.

For important, high-stakes use cases where a failed validation means the output can’t be used, re-asking is probably the most effective option I see people using.

Filtering is another option. Specifically for summarization or profanity filtering, if there are sentences that aren’t information-dense or contain profanity, you can have granular control and filter out those specific elements.

Another option, which is the default setting if you’re using Guardrails, is a mode where you still run all the validations on an LLM output, but if validation fails, you don’t do anything. You return the output as if the user were using an LLM without Guardrails, while logging everything that went wrong.

You can access that log and decide whether to iterate on your model or prompt. There are also options to raise an exception or deterministically fix the output when that’s possible.

Nathan Labenz

OpenAI recently launched its Evals library alongside GPT-4. My surface-level understanding is that it’s architected more as a benchmarking suite than as a runtime aid. What have you learned from it, and what did you think was smart about its implementation or approach to validating language-model outputs?

Shreya Rajpal

My interpretation is that it’s an offline framework that allows OpenAI to test internally how well its LLMs are doing on tasks people care about.

My favorite thing about it is not necessarily technical, but more related to product and go-to-market. It’s almost like a radio crowdsource of how people want to use their large language models, and all the ways those models are going wrong.

OpenAI takes that and makes it part of its training data set or evaluation framework, so the models themselves are trying to serve those use cases better.

I’ve seen people use it to look through the examples and find interesting prompts they can borrow. That’s a nice way to mine the library.

Nathan Labenz

I also thought it was a nice touch that OpenAI created a separate lane for GPT-4 API access for people who contributed to the Evals library.

How about Anthropic’s Constitutional AI approach? That’s obviously a training protocol rather than runtime validation, but do you see commonalities there, or have you taken inspiration from that approach?

Shreya Rajpal

The Constitutional AI work is interesting, but it goes back to what I said earlier: it’s essential to have deterministic checks and deterministic post hoc validation. Training alone isn’t sufficient.

Runtime verification and runtime validation are the most exciting problems to me. Another important aspect is configurability: being able to configure what correctness means to you and enforce that specifically, rather than relying on a globally understood or standardized definition of correctness.

I like a world where developers have the agency to configure what correctness means for them. Being able to do that in a post hoc setting, without retraining a model every time your definition of correctness changes for a particular use case, opens access to a much broader audience.

Nathan Labenz

I see an opportunity to bring Constitutional AI-style critique to runtime. I listened to one of the lead authors of the Diplomacy paper describing the Cicero model from Meta. He was discussing a general strategy for bringing more compute forward into runtime.

Older systems, such as Deep Blue playing chess, used extremely intensive runtime computation, essentially searching a large tree. With language models, it hasn’t been as obvious how to do that.

Rather than relying entirely on computation embodied during training, we could bring some of it forward into runtime and apply checks. The more compute you spend, the more likely you are to get good output.

You mentioned deterministic systems, but some of these approaches still aren’t deterministic. If I critique something repeatedly, there’s still an inherent layer of nondeterminism. It may reduce my problems, but there’s still stochastic behavior.

Shreya Rajpal

That’s a good point, and I should qualify what I mean by deterministic.

There are different ways to evaluate or validate outputs. One is to take an LLM output and create a new prompt asking GPT-4, “Is this output correct given these criteria?” You might ask for a yes-or-no response or another binary response that lets you assess it.

That’s one validation method, and it’s not deterministic at all. It is, however, an additional layer of security.

There are also rule-based or heuristic-based techniques, as well as validation rules that don’t use LLM APIs. You can use smaller, high-precision models trained on subsets of data. Even if the output is generated by a machine-learning model, you have more control over it and may be able to set random seeds or otherwise control its randomness.

When I say deterministic, I’m referring to an ensemble of all these techniques. Some are purely deterministic, while others are more deterministic in the sense that you have more control over the model and its behavior.

Nathan Labenz

One obvious question from a developer standpoint is what overhead this creates. You could measure that in several ways: token overhead, cost, complexity, latency, and perhaps tensions in the product experience.

I think about the Bing experience, where the system streams output token by token and then retracts it if it determines that it has gone off the rails. It’s remarkable that Microsoft launched with that paradigm.

I understand why. People don’t want to sit and wait for the whole thing to be generated before seeing what’s happening. There’s a powerful draw to the streaming experience—strong enough that Microsoft was willing to emit toxic content and then swipe it away.

How do you think about all those dimensions of overhead? How would you guide developers toward minimizing it? Are there things that can be done in parallel? What’s the smart version of this, given that many people will say, “The CEO says we can’t wait for that”?

Shreya Rajpal

It’s a good question. Interestingly, for specific applications, people are more comfortable with latency than you might expect. If they’re in a chatbot, that may be different, but if correctness matters and they’re getting high-quality output at the end, people are often willing to accept additional latency.

When I was initially building this, latency was a concern, and some of the design decisions supported that hypothesis. Re-asking, for example, doesn’t happen piecemeal. It aggregates the issues and then makes a request, so it’s a one-shot request from that perspective.

But people are generally comfortable adding some latency when correctness matters.

Token overhead is interesting. I’ve found a balance between how efficiently you can write a prompt using a structured prompting strategy and how efficient your prompts are when everything is written in words.

For some use cases, being able to structure your prompts is actually more efficient, even if you would expect it to require more tokens. All of the structure and constraints that might otherwise be represented in words can instead be represented with symbols or a domain-specific language, which can be much cheaper.

I’ve seen something similar with complexity. If you’re trying to get LLM outputs structured in a particular way or to have a certain behavior, the only way to do it today is to prompt manually and iterate a lot.

Guardrails abstracts some of that exploration away. There’s a domain-specific language that’s tested and works across multiple LLM providers. As a developer, you don’t have to figure out how to write a prompt that produces a specific structured output. You write it in a known way.

Even if you don’t care about validation and only care about getting structured outputs, Guardrails is useful. It’s a pain to think about how to do that, so you can use Guardrails to get structured outputs across different LLMs without writing and iterating on prompts yourself.

Nathan Labenz

Help people understand a little more about the complexity you’re taking out. How do you get the desired format back?

Shreya Rajpal

The entry point for developers is creating a spec. It’s a markup language where you specify an output schema.

If you want a particular output, you define all the components you want in that output. If it’s JSON, you can configure it as JSON. If it’s just a string with additional validation, you can configure that as well.

That’s separate from the prompt. You think about what output you want and how to define it from a schema perspective.

Guardrails has the Reliable AI Markup Language, or RAIL. In a RAIL spec, in addition to the output schema, you can have a separate prompt. All you need to add to the prompt is the higher-level task description.

Everything that describes how the output should be structured, what constraints it should satisfy, and how it should be formatted goes into the schema. That’s a programming language. If you can write XML or markup, you can write the schema without converting it all into English and experimenting to make sure the LLM API understands it.

Guardrails translates that specification into a prompt. The contract between the user and Guardrails is the spec, and it’s Guardrails’ job to translate that spec into the appropriate prompt.

As the behavior of a particular LLM changes, Guardrails can compile the same RAIL spec into different prompts. The user can provide the same high-level prompt and schema while Guardrails handles the model-specific translation.

From a developer’s point of view, you don’t have to wrangle model-version updates and model-quality issues to the same degree.

Nathan Labenz

That sounds really useful. I was doing some task automation yesterday and used the format trick. Everyone who works with language models has encountered it: “Use this format in the response.”

As far as I know, that came from OpenAI, and Riley Goodside popularized it. He attributes it to Boris Power, though I don’t know whether Boris came up with it independently.

I run into situations where I’m thinking about how intricate I want the format to be. Often I’ll say, “Use this format,” and then give it XML-like opening and closing tags. That lets me use a regular expression to parse whatever is inside the tags and remove any prefix, suffix, or “I hope this was helpful” text.

I haven’t gone much further than that, because then I’m hand-coding XML in the Playground or somewhere else, and that isn’t great. There’s a straightforward convenience factor in being able to write something at a higher level of abstraction and have the system translate it into a detailed prompt that produces the parsable result you want.

Speaker 1

I found that as well when I was prototyping. I prototyped with GPT-3, and anyone who has worked with GPT-3 or GPT-3.5 knows that you get things like, “Here’s the answer you’re looking for,” or “I hope that was helpful,” when all you want is the JSON.

Since the release of Guardrails, a community contributor has pushed an effort to add instruction tags and experiment with what works well with GPT-3.5. From a developer standpoint, you write one spec, and Guardrails handles the model-specific details.

With GPT-3.5, the prompt and output fields are handled separately, and people can get what they’re looking for without the additional filler that can make parsing fail.

Nathan Labenz

You’re also translating this to other models. That brings up a market dynamic. As people try to figure out where this is going, will we have one AI to rule them all, or many providers, or an oligopoly of large-language-model providers?

One force pulling everyone toward OpenAI is that so many systems are being developed against OpenAI’s state-of-the-art behavior at a given time. If you’re Anthropic, Cohere, Google, Aleph Alpha, or another provider, there’s a strong incentive to be as much like OpenAI as possible when it comes to supporting those capabilities.

But that raises the question of how you compete. If you have to spend all your energy making sure that people can switch to you without breaking the things they currently assume will work, that doesn’t seem like a great position.

Do you see that dynamic similarly? Does your experience lead you to think we’ll see concentration, if not of providers, at least in how language models behave?

Speaker 1

I personally believe there will be a lot of diversity among model providers. It’s almost insane to see the amount of activity and excitement in the space. I’ve worked in machine learning my entire adult life, but there are people training and fine-tuning deep-learning models who weren’t even in the space a few months ago.

That level of demand creates the need for more providers. I’ve had people say, “I really like Guardrails and I really like OpenAI, but it’s too expensive for what I’m trying to build. Can you make this work with an open-source model?”

I think we’ll see a lot of proliferation: great-performing models at different price points, with different latencies, from different providers. I’m excited about that world.

Another interesting aspect is that, because so much was unlocked by OpenAI, people are building frameworks around the most performant provider and model. That creates an incentive for other model providers to offer interoperability for those specific functionalities.

The standards are evolving at the same time as the models are getting better. There’s an interesting dynamic between them. For the foreseeable future, there’s a strong incentive for other model providers to offer similar functionality or at least avoid regressions.

That gives people an incentive to switch for a variety of reasons. The pace of innovation will eventually create a more level playing field, and then it will be interesting to see what specializations different providers and open-source models offer.

Nathan Labenz

I have 3 quick final questions. Answer them quickly or not at all.

First, what are your favorite AI apps, experiences, or tools that you’re loving and would recommend to others?

Shreya Rajpal

I recently had to set up my development environment from scratch. I didn’t have GitHub Copilot, and I thought, “What am I missing? Why am I coding slower?”

Nathan Labenz

I can totally relate to that. When Copilot stopped working because it became paid, I was in a panic until I realized I could simply pay for it and make it come back. I’m not going to be doing this without it now. That’s not something I’m willing to endure.

Second, imagine that at some point in the future, 1 million people already have Neuralink implants. If you could get one and control your computer and devices with your thoughts, would you be interested?

Shreya Rajpal

I would not. What if I’m in a presentation or something, controlling my laptop with my brain, and I get distracted? Does that mean my slide deck is suddenly showing whatever I’m distracted by?

There’s a need for layers of security between thinking and executing something on another system. I would skip it, but I’d be very excited to see that world. I’d be happy to inhabit that role even if I wasn’t actively participating in it.

Nathan Labenz

Great answer.

The final question is about society at large. Zoom out as far as you can and think as far into the future as you can. Do you have any sense of what might happen? What are your biggest hopes and fears for society as this AI moment continues to unfold?

Shreya Rajpal

My biggest concern is job displacement. I don’t think I have any special insight here, but I think about it quite a bit.

What is the amount of work that would still be valuable in a future where a lot of knowledge work can be assisted, or where knowledge workers can be made much more efficient than they are today? What does that mean for the future of work? That’s something I think about.

One hope is that I can live a life where I don’t have to do the mundane things that take up so much of our time. In the future, maybe I won’t have to do my own taxes or book my own flights. I could simply say, “Book this flight for me on this date, find me the best price, and so on.”

Being able to automate away many of those parts of life and focus on the fun parts is something I’m excited and hopeful about.

Nathan Labenz

Go check out the package if you’re building with large language models and facing issues where something was working and then stopped working. Check out Guardrails AI and follow Shreya on Twitter.

Shreya Rajpal, thank you very much for being part of The Cognitive Revolution.

Shreya Rajpal

Thank you again for inviting me. I really enjoyed talking with you.

与 Guardrails AI 的 Shreya Rajpal 一起让 AI 革命不脱轨 — 文字稿与摘要 | BidClub