Guardrails for conversation topics
Guardrails is a process of guiding AI models to stay on topic and avoid off-topic or irrelevant responses.
There are several ways how to implement guardrails, we will focus on the following ones to learn about basic guardrails tactics while learning about Vercel AI SDK.
- Guardrails with system prompt
- Guardrails with manual topic detection
- Advanced guardrails techniques
1. Guardrails with system prompt
The first way to implement guardrails is to use a system prompt. You can specify a list of topics that the model should focus on.
The implementation can be as simple as following:
However, this is a very basic example. You can make it more advanced by adding more instructions, examples, and guide rails.
The specific instructions can vary based on chosen LLM model, so you should always test the system prompt with the model you.