Quality & Reliability ⏱ 20 min to implement ✓ Production tested

Agent Output Validation Loop

Your agent produces output. You ship it. Three days later someone points out it was wrong, stale, or broken. You had no gate between "agent said it" and "user saw it." This playbook gives you a practical output validation loop — a quality gate that runs before any agent output hits a user, a file, or a channel. Tested in production on Patrick (CEO agent) and Miso (support agent) at Ask Patrick.

The Core Pattern: Generate → Validate → Gate

Every significant agent output goes through three stages:

GENERATE
VALIDATE
GATE

This is not about being slow. It's about never shipping broken output.

Stage 1: Generate

Your agent produces output as normal. The key is that output stays in a draft state until validated. In OpenClaw / file-based agents, write output to a .draft file first:

# agent writes to draft, not final destination
echo "$output" > /tmp/agent-output.draft

In Claude (via prompt), end with a COMPLETE signal as the trigger to begin validation:

Produce your response. When complete, add a final line:
STATUS: COMPLETE

Stage 2: Validate — The 5-Check Framework

Run these five checks on every significant output. Automate what you can.

Check 1: Format Integrity

Does the output match the expected structure?

import json

def check_format(output: str, expected_keys: list) -> bool:
    try:
        data = json.loads(output)
        return all(k in data for k in expected_keys)
    except json.JSONDecodeError:
        return False

For markdown outputs, check for required sections:

# Validate markdown has required headings
REQUIRED_SECTIONS=("## The Problem" "## The Solution" "## Implementation")
for section in "${REQUIRED_SECTIONS[@]}"; do
    if ! grep -q "$section" output.draft; then
        echo "FAIL: Missing section: $section"
        exit 1
    fi
done
echo "PASS: All required sections present"

Check 2: Claim Specificity

Vague outputs are worth nothing. Scan for weasel words:

VAGUE_SIGNALS = [
    "you might want to",
    "consider",
    "it depends",
    "various ways",
    "many options",
    "generally speaking",
    "typically",
    "usually works"
]

def check_specificity(text: str) -> list:
    found = [s for s in VAGUE_SIGNALS if s in text.lower()]
    return found  # empty list = pass

If you get hits, the output needs a revision pass: "Replace every instance of [VAGUE_SIGNAL] with a specific recommendation."

Check 3: Link Validity

Any URL in the output must return 200. Non-negotiable.

# Extract all URLs from output and check them
grep -oP 'https?://[^\s)]+' output.draft | while read url; do

Checks 3–5 + the Gate logic are inside

The rest of this item covers link validity checking, freshness scanning, length sanity — plus the complete Gate function (SHIP / RETRY / ESCALATE logic), the OpenClaw prompt wrapper Patrick runs in production, and the weekly metrics table.

  • bash script for URL validation (checks every link pre-ship)
  • Python freshness scanner (flags stale year references)
  • Word count thresholds by output type (library items, Discord, briefings)
  • Complete gate() function — pass/retry/escalate with retry prompt template
  • Full OpenClaw prompt wrapper for self-validating agents
  • Weekly metrics targets (first-pass rate, retry rate, escalation rate)
Get Library Access — $9/mo →

Includes all 40+ library items + Daily Briefing. 30-day money-back guarantee.

← Back to Library