QA
Beginner LevelAI, LLMs, Embeddings & MCP

What are LLM Guardrails (NeMo Guardrails, Llama Guard) for input/output safety?

❓ Interview Prompt: Explain input validation, output sanitization, topical boundaries, and PII masking using security guardrail layers.

LLM Guardrails are programmable security middleware layers that sit between user applications and LLM APIs to inspect, filter, and modify inputs and outputs.

Key Guardrail Responsibilities:

1
Input Guardrails: Detect prompt injection attempts, toxic inputs, and off-topic domain queries before sending to the model.
2
Output Guardrails: Scan generated responses for PII leaks (Social Security numbers, API keys), harmful content, or hallucinated facts.
3
Popular Guardrail Engines: NVIDIA NeMo Guardrails, Meta Llama Guard, Guardrails AI.

Code Implementation Example

typescript
function sanitizePII(output: string): string {
  // Redact SSN patterns
  const ssnRegex = /\b\d{3}-\d{2}-\d{4}\b/g;
  // Redact API key patterns
  const apiKeyRegex = /sk-[a-zA-Z0-9]{32,}/g;

  return output
    .replace(ssnRegex, '[REDACTED_SSN]')
    .replace(apiKeyRegex, '[REDACTED_API_KEY]');
}
💡Simple output guardrail function redacting sensitive PII and API keys.
🎯 Interview Key Takeaway

Guardrails act as security middleware, filtering prompt injections on input and redacting PII leaks on output.

#Guardrails#Security#PII#Sanitization#Beginner
Back to all AI, LLMs, Embeddings & MCP Questions→

More AI, LLMs, Embeddings & MCP Interview Questions

Beginner LevelAI, LLMs, Embeddings & MCP

What are Vector Embeddings and Cosine Similarity in AI Semantic Search?

Beginner LevelAI, LLMs, Embeddings & MCP

What is the Model Context Protocol (MCP) and how does it connect LLMs to external tools?

Beginner LevelAI, LLMs, Embeddings & MCP

What is Retrieval-Augmented Generation (RAG) and how does it prevent LLM hallucinations?