Guardrail wrappers add validation layers before and after the main model call. Input guardrails check for toxic content, PII, or injection attempts. Output guardrails verify the response meets safety, format, and content policies before returning it to the user.
if contains_pii(user_input): user_input = redact_pii(user_input) if is_toxic(user_input): return SAFE_REFUSAL_MESSAGE
response = call_llm(user_input)
if contains_pii(response) or violates_policy(response): return SAFE_FALLBACK_MESSAGE
return response
Claude handles Guardrail Prompt Wrappers tasks with excellent instruction compliance and structured output formatting.