Docs/Foundational Primitives/Safety Guardrails

Safety Guardrails Engine

The GuardrailEngine verifies user prompts before LLM execution and audits model outputs before returning responses to callers.

Input & Output Guardrail Rules

Select execution mode (**Gateway**, **Provider**, **Custom**) or pick models from the dropdown below:

1import { streamText, GuardrailEngine, Guardrails } from '@bablusingh-dev/agentcore';
2
3const guardrails = new GuardrailEngine()
4 .addInputRule(Guardrails.maxCharacterLength(2000))
5 .addInputRule(Guardrails.blockKeywords(['unauthorized']));
6
7const { textStream } = streamText({
8 model: 'anthropic/claude-3-5-sonnet',
9 prompt: 'Execute query with safety guardrails.',
10 guardrails,
11});
12
13for await (const textPart of textStream) {
14 console.log(textPart);
15}