Barreiras de segurança e avaliação de RAG
Bloqueie saídas inadequadas e meça a qualidade da recuperação.
Barreiras de segurança e avaliação de RAG é uma aula grátis de MLOps Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de MLOps Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de MLOps Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
LLMs Need Bumpers
Left alone, a model can leak data or go off-topic. Guardrails are checks around the model that keep inputs and outputs inside safe bounds. 🛡️
Validate the Input First
Before calling the model, screen the user message for prompt injection or banned content. An input guard stops bad requests from ever reaching the LLM.
Check the Output Too
After generation, scan the answer for toxicity, secrets, or wrong format. An output guard blocks or rewrites unsafe text before the user sees it.
if contains_pii(answer):
answer = "Sorry, I cannot share that."Enforce Structure
When you need JSON, validate it against a schema and retry on failure. A schema guard turns flaky free text into reliable, parseable output.
from pydantic import BaseModel
class Reply(BaseModel):
answer: str
confidence: floatGuardrail Libraries
Tools like Guardrails AI and NeMo Guardrails bundle these checks. A library gives you ready-made validators instead of hand-rolling every rule.
Now Meet RAG
Many LLM apps fetch documents and feed them to the model. This RAG pattern, retrieval augmented generation, grounds answers in your own data.
Two Things Can Break
RAG can fail at retrieval or at generation. So you evaluate the retriever and the answer separately, because fixing one will not fix the other.
Score the Retrieval
Ask whether the fetched chunks actually contain the answer. Context recall measures if the right information made it into the prompt at all.
Score the Grounding
Even with good context, the model may invent details. Faithfulness checks that every claim in the answer is backed by the retrieved text.
Score the Relevance
Finally, judge whether the answer addresses the question asked. Answer relevance rounds out the picture beyond just being grounded.
Frameworks Like RAGAS
RAGAS computes faithfulness, context recall, and relevance from your cases. A framework turns fuzzy RAG quality into numbers you can track over time.
from ragas import evaluate
result = evaluate(dataset, metrics=[faithfulness, context_recall])Quick Check
Your RAG bot answers confidently but invents facts not in the documents. Which metric flags this?
Recap
You added guardrails on inputs and outputs and learned to evaluate RAG with faithfulness, context recall, and relevance. Safe and grounded. You did it! 🎉
Perguntas Frequentes
A aula “Barreiras de segurança e avaliação de RAG” é grátis?
Sim — o texto completo de “Barreiras de segurança e avaliação de RAG” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de MLOps Academy, atualize para CoddyKit PRO. O curso de MLOps Academy inclui 4 aulas no total.
O que vou aprender em “Barreiras de segurança e avaliação de RAG”?
Bloqueie saídas inadequadas e meça a qualidade da recuperação. Você pratica MLOps Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar MLOps Academy?
Nenhuma experiência prévia é necessária. MLOps Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Barreiras de segurança e avaliação de RAG”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de MLOps Academy?
Sim. Cada aula de MLOps Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Como LLMOps difere do MLOps clássico
- Versione prompts e avalie saídas
- Rastreie e monitore chamadas de LLM
- Barreiras de segurança e avaliação de RAG