responds with
responds with
Declare the output contract for a machine. The responds with section defines what data a machine returns after execution. Each field has a name, type, and optional source mapping. The runtime validates the machine’s output against this contract, and callers can rely on the declared shape.
Replaces the legacy provides > outputs syntax. The parser accepts both forms; run mashin fmt to auto-migrate.
When to use
Every machine that produces output should have a responds with section. Omit it only for fire-and-forget machines (like notification senders) where the caller does not need a return value.
Syntax
responds with <field_name> as <type> <field_name> as <type>, <modifiers> ...Field declaration
Each field follows the pattern:
<name> as <type>, <modifier1>, <modifier2>, ...Types
Same types as accepts: text, string, number, integer, decimal, boolean, list, list of <type>, map, any.
Modifiers
| Modifier | Description | Example |
|---|---|---|
from <step_name> | Map this output field from a specific step’s output | summary as text, from analyze |
from state.<field> | Map from machine state | count as integer, from state.counter |
default <value> | Default value if the source field is null | done as boolean, default true |
Source mapping with from
The from modifier provides declarative output mapping. Instead of writing a final compute step to assemble the output, you can map output fields directly to step results or state:
responds with summary as text, from analyze confidence as number, from analyze attempt_count as integer, from state.retries, default 0 completed as boolean, default trueWithout from, output fields are populated from the last step’s return value. If the last step returns {summary: "...", confidence: 0.9}, those values map to matching output field names.
Examples
Simple outputs
responds with greeting as text timestamp as numberWith source mapping
machine research_assistant accepts question as text, is required
responds with answer as text, from search sources as list, from search cached as boolean, from state.was_cached, default false
implements state was_cached: boolean, default: false
ask search, using: "anthropic:claude-sonnet-4-6" with task "Research this question: ${input.question}" returns answer as text sources as list assuming answer: "Based on research..." sources: ["source1.com"]Typed lists
responds with items as list of text scores as list of number results as list of mapFull machine with responds with
machine sentiment_classifier accepts text as text, is required
responds with sentiment as text confidence as number keywords as list of text
implements ask classify, using: "anthropic:claude-haiku-4" with task "Classify the sentiment and extract keywords.\n\nText: ${input.text}" returns sentiment as text confidence as number keywords as list of text assuming sentiment: "positive" confidence: 0.92 keywords: ["great", "excellent"]Output validation
The runtime validates that the machine’s final output matches the responds with contract:
- All declared fields must be present in the output (unless they have a
default) - Field types are checked at runtime
- Extra fields not declared in
responds withare stripped from the output
If validation fails, the machine returns an error rather than invalid output. This protects callers from receiving unexpected data shapes.
Governance
Output validation is recorded in the behavioral ledger. If the output contract is violated (missing field, wrong type), the violation is recorded as a step event. This makes output contract violations auditable.
The responds with section itself has no governance cost. It is a compile-time declaration that the runtime uses for validation.
Translations
| Language | Keyword |
|---|---|
| English | responds with |
| Spanish | responde con |
| French | repond avec |
| German | antwortet mit |
| Japanese | で応答する |
| Chinese | 回应返回 |
| Korean | 로 응답한다 |
See also
- accepts - Input contract declaration
- implements - Where steps produce output values
- verifies - Test cases that assert output via
expect - achieves - Goal examples with expected outputs