Check the output

Pass or fail in code

A guardrail returns a pair: True keeps the result, False sends back a short reason.

Instructions ask the model to behave. A guardrail is code that checks what came back.

Press Try it Yourself to run the check on a fixed sentence.

Example

class Result:
    raw = "An agent takes a role, then a task."

def short_enough(output):
    text = output.raw
    if len(text) <= 400:
        return (True, output)
    return (False, "Too long")

passed, value = short_enough(Result())
print("Passed:", passed)
print(value.raw)

Try it Yourself

Example explained

  • (True, output) — The check passed. Keep the result.
  • (False, message) — The check failed. The message says why.

Reference: documentation