Skip to content

Model guardrails

Add input and output safety checks around the models you call on Mango Inference.

No guardrails by default

Mango Inference does not document any built-in content filtering, and the /v1/moderations endpoint is not supported. A model answers what it is asked. Guardrails are something you add, in your application or in a gateway in front of it. This is the same default most hosted-inference providers use, for example Fireworks AI.

Where guardrails go

user input ──► input check ──► model call ──► output check ──► user
                  │                              │
               block / rewrite              block / redact

Check the input to catch prompt injection and disallowed requests before you spend tokens. Check the output to catch unsafe, off-policy or leaked content before a user or a downstream tool sees it. For agents with tool calling, also validate tool arguments before you execute them.

Options

Approach What it is Notes
Safety classifier model A model such as Llama Guard that labels a prompt or response as safe or unsafe. Call it through the same API as any other model. Check GET /v1/models for what your key can call; availability is not assumed here.
AI gateway A proxy (for example Portkey) that applies guardrails to every request and response. Point the gateway at https://api.mangoboost.io/v1 as an OpenAI-compatible upstream.
Your own rules Regexes, allow-lists, PII redaction, JSON-schema validation of outputs. Cheap and deterministic. Pair with structured output.

Example: classifier check around a call

This assumes a safety classifier is available to your key. Replace the model IDs with ones that GET /v1/models returns.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.mangoboost.io/v1",
    api_key=os.environ["MANGOINFERENCE_API_KEY"],
)

GUARD_MODEL = "<safety-classifier-model-id>"  # TODO: verify an available model


def is_safe(role: str, text: str) -> bool:
    verdict = client.chat.completions.create(
        model=GUARD_MODEL,
        messages=[{"role": role, "content": text}],
    ).choices[0].message.content
    # Classifier output formats differ by model; Llama Guard replies
    # "safe" or "unsafe" plus a category.
    return verdict.strip().lower().startswith("safe")


def guarded_chat(prompt: str) -> str:
    if not is_safe("user", prompt):
        return "Sorry, I can't help with that."
    reply = client.chat.completions.create(
        model="zai-org/GLM-5.3",
        messages=[{"role": "user", "content": prompt}],
    ).choices[0].message.content
    if not is_safe("assistant", reply):
        return "Sorry, I can't share that response."
    return reply

Best practices

  • Match guardrails to your use case; a coding agent and a public chatbot need different policies.
  • Fail closed: if the guard call errors or times out, block rather than pass the content through. See reliability.
  • Log blocked requests with the x-request-id header, never the content unless your policy allows it.
  • Monitor outputs continuously and review your policies on a schedule.
  • Never put secrets in prompts; see data privacy and security.