The Truth About AI Guardrails

Hamel Husain explains how AI guardrails work and why most off-the-shelf ones fail. A guardrail is just a prompt asking if a response makes sense. Developers need to customize them for their product because generic guardrails won't catch what matters to you.
Chapters
If you're building AI products, you may have heard of the term guardrails. So what is a guardrail? Guardrail is something that is meant to protect you from something bad your AI might be doing, such as talking about competitors or going off topic or using profanity. And it's worth knowing what exactly a guardrail is and how does it work. I'm going to share my screen here. And what we have here is a very popular framework, Guardrails AI, and they have a guardrails hub. And this is a very popular way to use guardrails in your application. And so if we go here, you'll see a whole bunch of guardrails. All kinds of risk categories. I'll click on brand risk and we'll see all kinds of things, guardrails for that, like competitor check, detecting gibberish. I'm going to go ahead and select QA relevance just because question answer relevance is important in a lot of applications. And so what is this guardrail? This is a validator that checks whether an answer that your AI is giving is relevant to the question that is asked by the user. And say, what does this mean? How does it work? So let's go ahead and look at the code. Click on validator and then I'm going to click on main and And this is the code for that QA relevance guardrail. So scroll all the way down here. So this guardrail is this prompt which says, is the above response relevant to the following prompt? So this guardrail is just someone else's prompt. That's all it is. You could use something exactly like this by just writing this prompt yourself. In fact, if you were to use this guardrail, this is about 5 levels of abstraction just to get this one sentence prompt. So the thing to know about guardrails is all you're doing is using someone else's prompt. And you have to ask yourself, is that really going to do what you want? A lot of times that off-the-shelf prompt is not specific enough to your product to do a good job. In this case, this is just a very simple sentence that says, hey, is the response relevant? So it's worth knowing what a guardrail is, and it's not a 100% guaranteed solution to catching errors. If you want to learn more things like this, I left some resources in the comments.










