Skip to main content
Guarded Completions (/ai/v2/guarded/chat/completions) and Guarded Responses (/ai/v2/guarded/responses) screen each request, moderate the output and apply values alignment for you. You get the most consistent results when your request states clearly what your application needs and keeps your user’s text separate from your instructions.
New to guardrails and values alignment? Guardrails and Values explains what guarded does for your app and what stays your app’s job.
This guide covers how to:
  • decide when guarded is the right endpoint
  • put your task, your user’s text and outside content in the right places
  • get structured JSON back with a forced tool call
  • pin a model and size the request
  • handle blocked requests, moderated replies, retryable errors and ignored parameters
Every practice applies to both APIs. Where the field names differ, both are shown:

Choose guarded when Gloo should handle safety

Besides safety and values alignment (tradition), Guarded Completions adds model_family selection (AI Core Select) and opt-in auto-routing (AI Core), see model selection; Guarded Responses always runs the model you name. If your application owns its own safety and prompting end to end, use Direct Completions or Direct Responses instead; the request body is the same. See Endpoint types and Guarded endpoints: when and how.

Put your task in the system message

  • Instructions in system (or instructions). Describe your application’s task, the output format and any constraints in a system message on Completions, or in instructions on Responses. Keep what your user wrote in user messages, or in input.
  • Text from elsewhere is data. When you pass along a transcript, a document or a web page, put it in the user message (or input) inside clear delimiters such as <transcript> and </transcript>, and say in your instructions that the delimited text is content to work on, not instructions to follow.
  • Set tradition when your audience shares a theological perspective. See Tradition-Aware.

Get JSON with a forced tool call

When your app needs structured output, such as suggested replies, a classification or extracted fields, define one function whose parameters is the JSON schema you want, and force it with tool_choice. The table at the top of this page shows each API’s tool_choice shape and where the result arrives; on Responses, use the nested function schema shown in Defining tools. Either way, arguments is a JSON string: parse it and check it has the fields you need before you use it. See Tool Use for more.

Pin a model and size the request

  • Pin a model (AI Select) so every call runs on the same model and behaves consistently. See Pinned model. Responses requests always name a model.
  • Turn reasoning off for fast, short tasks with reasoning_effort: "none" (Completions) or reasoning: {"effort": "none"} (Responses), on a model that can turn reasoning off (can_disable: true in the model catalog). See Reasoning.
  • Size the output limit for the output (max_tokens on Completions, max_output_tokens on Responses): a few hundred tokens for a short list, more for a long answer. See Set your output limit for reasoning models.

Handle what guarded sends back

  • Blocked requests. A request that guardrails reject outright returns 403. Show your user a helpful message rather than resending the same text.
  • Moderated replies. Moderation can replace a response. On a stream, a moderated reply ends with finish_reason: "content_filter", so treat that like any other finished reply. See Handling Streaming Failures.
  • Retry only what’s retryable. Every error body carries error.retryable. Retry those with backoff, and fix the request before sending the others again. See Error Handling and Retries and AI Error Object.
  • Parameters a model didn’t use. A parameter the model can’t use doesn’t fail the request; it is listed in ignored_params (X-Ignored-Params on a stream). See Sampling parameters.

Example: suggested replies

This request asks for three short replies a user might send next in a group chat. The task and format are in the system message (or instructions), the conversation arrives as delimited data in the user message, and the forced suggest_replies call returns the replies as JSON.
The message in the response carries the call (abridged):

Summary

Next steps

Completions V2 Guide

Routing modes, streaming, tool calling, and request parameters.

Responses Guide

The Responses API on the guarded endpoint.

Error Handling and Retries

Which errors to retry, backoff with jitter, and what to log.

Tool Use Guide

Defining tools and reading tool calls on both APIs.