A function check

Length

A check looks at the answer and says yes or no. Yes keeps the answer. No sends back a short reason.

This page runs the check on a sentence you can see. Passed means yes. The next line is the sentence that was kept.

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.

Too long fails

Lower the limit so this sample fails.

Example

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

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

passed, _ = short_enough(Result())
print("Passed:", passed)

Try it Yourself

Example explained

  • def short_enough — Defines `short_enough` used directly in the too long fails workflow.

Reference: documentation