Skip to content

Transformers

An agent gave you its answer. Before a downstream exposure node dispatches it (Slack, Jira, webhook), you may want to: - Extract a structured field from the free-text response - Assert that the output meets a quality gate before dispatch - Scrub PII from the text - Rewrite it into a specific format

That is what transformers do — a standalone transformers/*.yaml resource, referenced by name from transformers: on the agent whose result should pass through it. They run after that agent and before any downstream exposure node dispatches its result, in transformers: list order.

When to use transformers vs agent output_schema and other gates: - output_schema on the agent (structured output) — constrain the model to a Pydantic contract for the whole run; the agent's own transformers still receive the assistant text (and any structured payload) to forward downstream. - json_extract — parse JSON from mixed or fenced assistant text and optionally validate it with a JSON Schema file (schema_file); use when you do not want to change the agent definition. - assert or llm_guard — deterministic checks or an LLM pass/fail gate on the agent's output string before a downstream exposure node dispatches it; see sections below.

Transformers are optional steps that run after the agent finishes and before its result reaches any downstream exposure node. They reshape or validate the agent's text response: formatting, PII redaction, JSON extraction, deterministic checks, or LLM-based guardrails.

Declaring and referencing a transformer

Like retrievers, a transformer is defined once as a standalone catalog file, then referenced from any agent that wants it applied to its own result:

# transformers/pii_redact.yaml
name: pii_redact
type: pii_redact
config:
  types: [email]
  strategy: redact

Save this as agents/refund.md:

---
description: Resolves a refund request
transformers: [pii_redact]     # applied to refund's own result before the workflow's refund_api exposure node fires
---
Resolve the refund.

Execution flow

sources → compose user message → retrievers → agent → transformers → exposures
  • Retrievers enrich the prompt before the agent (see Retrievers).
  • Transformers run on the agent's final text after a successful run, and only gate exposure nodes downstream of that agent — a transformer on refund never touches close-ticket's result.

Transformers execute in transformers: list order. Each step receives the string produced by the previous step.

Transformers run under abt dispatch. abt run -s <agent> skips them.

CLI output: when a transformer will rewrite the text, live streaming of the raw response is suppressed and only the final transformed result is printed. Use abt dispatch --skip-transformers to bypass all transformers for a given run.

Ordering tip: run cheap deterministic steps first (assert, json_extract, pii_redact, regex_replace), then LLM steps (llm_guard, llm_rewrite) last.

YAML schema

Each transformers/*.yaml file has:

Key Required Meaning
name Yes Referenced from an agent's transformers: list
type Yes Built-in or custom provider name
credentials No Profile credentials namespace (rare for builtins)
config No Provider-specific mapping
prompt For llm_rewrite (or system_prompt) Prompt stem only (matches a file under prompts/, same name-only rule as a workflow prompt node). Mutually exclusive with system_prompt.
system_prompt For llm_rewrite (or prompt) Inline instruction, used verbatim: no {{ var() }} templating and no prompts/ lookup. Mutually exclusive with prompt.
model_id No Override chat model for LLM transformers, in provider:model form
temperature No Override temperature for LLM transformers
description No Human-readable summary
tags No Tags for docs and catalog filtering

Keys the transformer type doesn't read are ignored. abt compile does not check that a schema_file or a prompt: stem exists, or that llm_rewrite has a prompt.

Built-in transformers

assert

The free checks from abt test that look at the text: contains, not_contains, matches, json_schema, python. Use llm_guard for natural-language criteria.

# transformers/gate.yaml
name: gate
type: assert
config:
  on_fail: block   # block (default), warn, or skip
  checks:
    contains: [severity]
    matches: ["(?m)^## "]
    json_schema:
      type: object
      required: [status]
    python: ['"error" not in text.lower()']

A python check expression is not sandboxed: it runs with full interpreter access, in the trust model of the project (see Testing).

  • on_fail: block — fails the run (result.ok = False); exposures are not dispatched, on_failure handlers fire.
  • on_fail: warn — logs a warning; text passes through unchanged.
  • on_fail: skip — exposures are not dispatched, but result.ok stays True and on_success handlers fire. For a deliberate skip (e.g. no actionable content to post), not a failure.

json_extract

Parses JSON from the response (plain, fenced ```json, or first {), then returns canonical JSON as a string. Optional schema_file: path to a JSON Schema file (relative to project root).

# transformers/to_json.yaml
name: to_json
type: json_extract
config:
  schema_file: schemas/response.schema.json

pii_redact

Regex-based PII handling. types: email, credit_card, ip, phone, ssn (omit to apply all). strategy: redact (default) or block (fail if any match).

regex_replace

pattern, replacement, optional flags (IGNORECASE, MULTILINE, …).

llm_guard

Yes/no LLM gate, the same judge as says in abt test: the text passes when the judge agrees it does what criteria says. Text is unchanged if it passes.

# transformers/safe.yaml
name: safe
type: llm_guard
config:
  criteria: "does not give medical or legal advice"
  on_fail: block   # or warn, or skip

Same on_fail: block | warn | skip semantics as assert above.

llm_rewrite

Rewrites the text with a custom instruction (Slack formatting, summarization, etc.). Give the instruction inline with system_prompt: — unlike an agent's own system_prompt, this is used completely verbatim: no {{ var(...) }}/{{ source(...) }} templating, no prompts/ lookup.

# transformers/slackify.yaml
name: slackify
type: llm_rewrite
system_prompt: |
  Reformat the input as a concise Slack message. Use mrkdwn, not Markdown.
model_id: openai:gpt-4.1-mini
temperature: 0.2

Alternatively, prompt: takes a prompt stem — the same name-only reference used for a workflow's prompt nodes — and resolves it against prompts/<stem>.md (or any nested path with a unique basename) at dispatch time. prompt: and system_prompt: are mutually exclusive; set one.

# transformers/slackify.yaml
name: slackify
type: llm_rewrite
prompt: slack_format
model_id: openai:gpt-4.1-mini
temperature: 0.2

Custom providers

Register with @transformer_provider("my_type") and a transform(*, text, config, project_root, credentials) -> str method (raise to block output). Discover via:

  • Project providers/*.py (same pattern as retrievers), or
  • Setuptools entry point group abt.transformer_providers.

Decorate the instance, not the class — a bare class also passes the hasattr(cls, "transform") check but crashes at call time missing self:

# providers/my_transformer.py
from abt.transformers.registry import transformer_provider

class MyTransformer:
    def transform(self, *, text, config, project_root, credentials) -> str:
        return text.upper()

my_transformer = transformer_provider("my_type")(MyTransformer())
# transformers/shout.yaml
name: shout
type: my_type

Reference it from an agent the same way as any built-in: transformers: [shout].

Raise TransformBlockedError from abt.transformers to block dispatch without dispatching outputs.

Interaction with agent output_schema

Structured output validation tied to the agent is still handled at agent compile/run time (see Agents). Transformers operate on that same agent's own text output, right before it reaches a downstream exposure node; use json_extract or assert here for an extra gate before Slack/Jira/etc.

See also

  • Agents — the full frontmatter field reference
  • Exposures — where the transformed result goes next, and the exposure-timing rule
  • Retrievers — pre-agent enrichment
  • Testing — abt test assertions