Loading...
const reply = await llm(prompt);
await db.orders.update(JSON.parse(reply));const reply = await llm(prompt);
const result = OrderUpdate.safeParse(JSON.parse(reply));
if (!result.success || !canEdit(user, result.data.orderId)) {
log.warn('guardrail_blocked', { userId: user.id });
return 'Sorry, I cannot make that change.';
}
await db.orders.update(result.data);Validating the output with a schema and checking permissions in code stops bad or injected output from reaching the database.
Moderation is one kind of guardrail. Guardrails also include schema validation, tool restrictions, rate limits and permission checks.
It helps, but it is not reliable on its own, because prompts can be bypassed. Enforce critical rules in application code.
Some do, especially extra model calls. Fast checks like schemas and regex add little delay, and slower checks can run in parallel.