Tutorial: generate, validate, retry
A model’s own confidence is an opinion. When you have something firmer than an opinion
(a format rule, a schema, a linter, a validator service), you would rather the step loop
on that: generate, validate deterministically, and if it fails, try again with the
errors in front of the model.
This tutorial builds that in a single step. No second “gate” step, no verdict cache, and no instruction asking the model to report a lower confidence when it knows it failed.
It is standalone: the quick start and the stock
generic-pipeline-step agent, which needs no MCP tools.
What you’ll build
Section titled “What you’ll build”A generate-validate-retry pipeline with one step. The agent suggests a name for a service.
A shell check then tests the name against a rule the prompt deliberately does not state
up front (3–20 characters, lowercase letters, digits and hyphens, starting with a letter).
The first attempt usually breaks it. The check’s failure text is fed back, and the next attempt
fixes exactly that.
Prerequisites
Section titled “Prerequisites”-
The quick start completed, with an agent that can reach a model (
generic-pipeline-stepworks). -
Shell checks enabled. They are off by default because a
type: shellcheck runs a command through the real shell, unsandboxed. Inconfig.yaml:security:allow_shell_checks: trueRestart VectorStep to pick it up. (If you would rather not enable shell checks, the same pattern works with a
type: webhookcheck against a validator service: see Native JSON in a webhook payload and thewebhook-verdict-gate.yamlsample.)
1. Write the pipeline
Section titled “1. Write the pipeline”The pipeline ships as a sample. Copy generate-validate-retry.yaml into your pipelines directory,
or write pipelines/generate-validate-retry.yaml:
name: generate-validate-retrydescription: One step that generates a service name, validates it deterministically, and retries with the validator's errors until it passesversion: 1stage: testing
trigger: match: test: generate-validate-retry
context_template: include: - summary
steps: - name: name-the-service executor: gateway executor_config: agent: generic-pipeline-step confidence_threshold: 0.6 on_low_confidence: escalate
loop_until: checks_pass: true max_iterations: 3
prompt_template: | Suggest a name for this service: {{ summary }}
{% if loop.iteration > 1 %} Your previous suggestion was rejected by an automatic validator: {% for c in loop.prior_checks %} - {{ c.name }}: {{ c.detail }} {% endfor %} Previous answer: {{ loop.prior_output.service_name }} Fix exactly what the validator complains about. {% endif %}
Respond with ONLY this JSON: { "confidence": 0.0, "summary": "One sentence on why this name fits", "next_step_context": "", "service_name": "the name" }
deterministic_checks: - type: shell name: service-name-format run: | printf %s {{ output.service_name }} | grep -Eq '^[a-z][a-z0-9-]{2,19}$' || { echo "service_name must be 3-20 characters: lowercase letters, digits and hyphens, starting with a letter. Got: "{{ output.service_name }} exit 1 } expect: "exit_code == 0"Three things are doing the work:
output.service_namein the check. A check can read the step’s own output asoutput.*(the same fields later steps see assteps.name_the_service.*). Before this, a check could only look at earlier steps, which is why validating a step’s result used to take a second step. VectorStep shell-quotes every{{ }}value inrun, so whatever the model put inservice_nameis always one literal argument, never shell syntax.loop_until: {checks_pass: true}. After each attempt the checks run; the step repeats until they all pass ormax_iterationsis reached.loop.prior_checksin the prompt. The previous attempt’s failed checks, as a list of{name, type, detail}. For a shell check the detail is the command’s output, which here is the rule and what the model actually sent. Guard it withloop.iteration > 1: on the first pass the list is empty.
Reload:
curl -X POST http://localhost:8000/reload \ -H "Authorization: Bearer $(grep VECTORSTEP_ADMIN_TOKEN ~/.vectorstep/.env | cut -d= -f2)"2. Trigger it
Section titled “2. Trigger it”curl -X POST "http://localhost:8000/webhook?source=generic&allow_testing=true" \ -H "Authorization: Bearer $(grep VECTORSTEP_WEBHOOK_TOKEN ~/.vectorstep/.env | cut -d= -f2)" \ -H "Content-Type: application/json" \ -d '{ "pipeline": "generate-validate-retry", "summary": "A service that sends invoice reminders" }'3. What to look for
Section titled “3. What to look for”Open the run in the UI (or read the run log). Your wording from the model will differ, but the shape is always the same:
- Attempt 1 proposes something natural, such as
InvoiceReminderPro. It breaks the rule (capitals), so the check fails. The run log showsDeterministic check FAILED: service-name-format (shell) — exit code 1: service_name must be 3-20 characters ... Got: InvoiceReminderPro. - Attempt 2 receives that exact text through
loop.prior_checksand answers with something likeinvoice-reminder. The check passes. (This walkthrough was run againstopenai/gpt-4o-minithrough OpenRouter and behaved exactly like this: two attempts, then converged.) - The log records
loop_iterationfor the second attempt, thenRefinement loop converged: name-the-service — confidence …, checks passing after 2 iteration(s).
If a model got it right first time, you see a single attempt and no loop_iteration entry:
the loop only repeats while something is unmet. To see the retry deterministically, make the
rule stricter than the prompt hints at (for example require a svc- prefix).
Open the step on the run page: the Loop rounds panel lists how many rounds it took and why
each one repeated. The run API returns the same record as the step’s loop field (VectorStep
v0.1.28 or later):
"loop": { "iterations": 2, "max_iterations": 3, "history": [ {"iteration": 1, "confidence": 0.9, "checks_passed": false, "tokens": 416, "failed_checks": [{"name": "service-name-format", "type": "shell", "detail": "exit code 1: ..."}]}, {"iteration": 2, "confidence": 1.0, "checks_passed": true, "tokens": 474, "failed_checks": []} ]}Only the final attempt’s prompt and output are stored in full.
4. What happens when it never passes
Section titled “4. What happens when it never passes”Make the check impossible (say grep -Eq '^never$') and run again. After three attempts the step stops
looping and goes through the normal gate: a failed deterministic check forces trust to zero, so
the run escalates, exactly as a failed check does on any other step. The validator’s last complaint is
in the trust report on the run page. Nothing about the loop weakens the gate; it only gives the step
more chances before the gate decides.
Good to know
Section titled “Good to know”- Cost. Every attempt is a full agent call, and an attempt that fails its check still
costs. The step’s tokens and cost, and
budget.max_usd, count every attempt, not just the last. Keepmax_iterationssmall. - Confidence too.
loop_untilcan takeconfidence:alongsidechecks_pass:; the loop then continues while either is unmet. - Not a retry.
retry:re-runs a step after an error (timeout, provider failure). A failed check is not an error; it only uses a loop iteration. - Human checks inside a loop would ask for approval on every attempt. Prefer shell and webhook checks.
- Replay evaluates a candidate’s checks against the candidate’s own output, the same way production does.
Where next
Section titled “Where next”- Flow control: looping until your own checks pass
— the full reference, including every
loop.*variable. - Deterministic checks
— shell, webhook and human checks,
output.*, and native-JSON payloads. - Adding trust, one signal at a time — where a deterministic check sits among the other trust signals.