Consequence preview

Agents send what an action will do: the rendered email, the diff, the SQL with its dry-run row count, or the records it touches. People see it before they decide, and checks hold any preview that contradicts the request.

A summary is the agent describing what it will do. A preview is the thing itself: the email as it will go out, the diff, the SQL with the row count a dry run found, or the records the change touches. The agent’s code makes it before asking and sends it with the request. The person deciding sees it in the inbox, next to checks that compare it with the rest of the request.

A request in the inbox from cleanup-agent to delete 3 inactive test accounts. A red notice says the summary says 3 inactive test accounts, but the preview touches 4,812 rows. Below it the SQL preview shows 4,812 rows affected by a DELETE FROM customers.

The five kinds

Send one preview per request in the preview field. Its kind says how the inbox shows it:

{ "kind": "email", "to": ["ana@acme.com"], "cc": [], "bcc": [],
  "subject": "Your refund for order 4412", "body": "Hi Ana, …" }

{ "kind": "diff", "patch": "diff --git a/src/billing.ts b/src/billing.ts\n…" }

{ "kind": "sql", "statement": "UPDATE plans SET price = 12 WHERE id = 3",
  "rows_affected": 1, "plan": "Index Scan using plans_pkey on plans" }

{ "kind": "records", "title": "Customers to delete",
  "columns": ["id", "email", "last_seen"],
  "rows": [["c_118", "old@example.com", "2024-02-01"]], "total": 412 }

{ "kind": "text", "title": "Post to #general", "body": "Deploy 2.4 is out." }
email
to (1 to 50 addresses), cc and bcc (up to 50 each), subject (up to 500 characters) and the plain-text body (up to 20,000). Blind copies are marked, since the other recipients never see them.
diff
A unified diff such as git diff prints, up to 60,000 characters. The inbox lists each file with its added and removed lines.
sql
The statement (up to 10,000 characters), rows_affected from a dry run, and the query plan if you have one.
records
A small table: 1 to 20 columns, at most 50 rows of text, numbers, true/false or null, and total for how many records the change touches in all.
text
Anything else as it will appear, such as a chat message or a post, with an optional title like Post to #general.

Unknown fields are refused, and so is a preview over these limits. The whole request must still fit the API’s 64 KB body limit, so a very large diff belongs in a summary of its files plus the parts that matter.

What is checked

Every check compares the preview with the summary, the action and the details the agent sent. They are plain rules, not a model, so the same request always gets the same findings.

Recipients
The preview sends to an address neither the summary nor the details name, blind-copies someone the summary leaves out, or misses an address the details send to.
Counts
“Delete the 3 test accounts” over SQL whose dry run touched 4,812 rows, records with a total of 412, or a diff of 9 files where the summary says 2.
Action
The SQL deletes, but the action is database.update; or it writes when the action says read.
Sensitive
A DELETE or UPDATE with no WHERE (also inside a CTE), a DROP or TRUNCATE, SQL the check cannot read such as CALL or a DO block, or a diff that changes an environment file, a CI workflow, the code owners file, a key file, a git hook, or an AI agent's own settings (.claude, .codex, .cursor, .gemini, .mcp.json) without the summary naming it.
Hidden characters
Characters in the preview nobody can see.

What a finding changes

  • People see the preview and each finding in a sentence. The agent is only told the request waits, so it cannot learn how to word its way past a check.
  • No allow rule approves a request with a preview finding on its own: a person decides. deny rules still deny.
  • A preview never approves anything. A request with a clean preview is decided exactly as one without a preview.

The preview is the agent’s own claim about what will happen. It helps you see what you approve, and the checks catch it contradicting the request, but it cannot prove the tool will do the same thing. For that, have the tool check an approval receipt before it acts, and run exactly the statement or diff that was previewed instead of producing a new one after the approval.

Sending a preview

A request that says 3 accounts while the dry run found 4,812:

{
  "agent": "cleanup-bot",
  "action": "database.delete",
  "summary": "Delete the 3 test accounts",
  "preview": {
    "kind": "sql",
    "statement": "DELETE FROM accounts WHERE email LIKE '%test%'",
    "rows_affected": 4812
  }
}

People in the workspace read it back with the preview and its findings in preview_checks:

"preview": {
  "kind": "sql",
  "statement": "DELETE FROM accounts WHERE email LIKE '%test%'",
  "rows_affected": 4812,
  "plan": null
},
"preview_checks": [
  {
    "kind": "preview_count",
    "says": "The summary says 3 test accounts, but the preview touches 4,812 rows."
  }
]

With the TypeScript package:

import { ApprovalClient } from "@variantgate/agent";

const approvals = new ApprovalClient({ apiUrl, key, agent: "cleanup-bot" });
const statement = "DELETE FROM accounts WHERE email LIKE '%@test.example'";
const rows = await dryRun(statement); // inside a transaction you roll back

await approvals.guard(
  {
    action: "database.delete",
    summary: `Delete the ${rows} test accounts`,
    preview: { kind: "sql", statement, rows_affected: rows },
  },
  () => db.query(statement)
);

With the Python package:

from variantgate import require_approval

statement = "DELETE FROM accounts WHERE email LIKE '%@test.example'"
rows = dry_run(statement)  # inside a transaction you roll back

preview = {"kind": "sql", "statement": statement, "rows_affected": rows}
with require_approval("database.delete", f"Delete the {rows} test accounts", preview=preview):
    db.execute(statement)

With curl:

curl https://api.variantgate.com/v1/requests \
  -H "Authorization: Bearer $VARIANTGATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "mail-bot",
    "action": "email.send",
    "summary": "Send Ana the refund confirmation for order 4412",
    "details": { "to": "ana@acme.com" },
    "preview": {
      "kind": "email",
      "to": ["ana@acme.com"],
      "subject": "Your refund for order 4412",
      "body": "Hi Ana, we refunded 49.00 EUR to your card."
    }
  }'

Both packages check a preview against the limits before sending it and refuse one that does not fit, instead of cutting it: a shortened diff would show less than the change does.

Producing a good preview

  • SQL: run the statement inside a transaction you roll back, or a SELECT count(*) with the same WHERE, and send that count as rows_affected. Add the EXPLAIN output as plan when a full scan would matter.
  • Email: render the final template with the real recipient, not the prompt the model was given, and send exactly what the mail client will send.
  • Diff: git diff --cached of the change the agent is about to commit or push.
  • Records: select the rows the change touches, the first 50 in the table and the full count as total.
  • Make the preview in code, from the same values the action will use. A preview the model writes is only another summary.

Older API versions

An API from before previews refuses a request with a preview field (422), because request bodies take no unknown fields. During a deploy with several instances, send previews only once every instance is updated. The hosted service is.

Related: the summary check compares the summary with the details, and sources show what the agent read before it asked. Try a preview without signing up in the playground.