Skip to content
Beta. VectorStep is in beta.Let us know if something breaks.

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.

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.

  • The quick start completed, with an agent that can reach a model (generic-pipeline-step works).

  • Shell checks enabled. They are off by default because a type: shell check runs a command through the real shell, unsandboxed. In config.yaml:

    security:
    allow_shell_checks: true

    Restart VectorStep to pick it up. (If you would rather not enable shell checks, the same pattern works with a type: webhook check against a validator service: see Native JSON in a webhook payload and the webhook-verdict-gate.yaml sample.)

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-retry
description: One step that generates a service name, validates it deterministically, and retries with the validator's errors until it passes
version: 1
stage: 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_name in the check. A check can read the step’s own output as output.* (the same fields later steps see as steps.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 in run, so whatever the model put in service_name is 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 or max_iterations is reached.
  • loop.prior_checks in 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 with loop.iteration > 1: on the first pass the list is empty.

Reload:

Terminal window
curl -X POST http://localhost:8000/reload \
-H "Authorization: Bearer $(grep VECTORSTEP_ADMIN_TOKEN ~/.vectorstep/.env | cut -d= -f2)"
Terminal window
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"
}'

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:

  1. Attempt 1 proposes something natural, such as InvoiceReminderPro. It breaks the rule (capitals), so the check fails. The run log shows Deterministic check FAILED: service-name-format (shell) — exit code 1: service_name must be 3-20 characters ... Got: InvoiceReminderPro.
  2. Attempt 2 receives that exact text through loop.prior_checks and answers with something like invoice-reminder. The check passes. (This walkthrough was run against openai/gpt-4o-mini through OpenRouter and behaved exactly like this: two attempts, then converged.)
  3. The log records loop_iteration for the second attempt, then Refinement 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.

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.

  • 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. Keep max_iterations small.
  • Confidence too. loop_until can take confidence: alongside checks_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.