Respond
Use Respond to stop execution and return a custom HTTP response to the workflow caller.
Overview
Type: respond
Set the HTTP status, body, and optional headers. The caller receives the configured body directly, without the normal workflow execution envelope. Keep Respond outside Batch because Batch handles child errors internally.
Configuration
Status
- Type: Number
- Required: No
- Default:
200 - Min:
100 - Max:
599 - Description: HTTP status code to return
Code
Body
- Type: Object
- Required: Yes
- Templatable: Yes
- Description: Response body (automatically processed with Morpher)
Body fields can contain nested objects, arrays, and template values:
Code
Headers
- Type: Object (Key-Value pairs)
- Required: No
- Templatable: Yes
- Description: Custom HTTP response headers
Code
Behavior
A Respond step in the top-level sequence terminates that sequence. In a Rule or Map, its response also propagates out of the workflow, unless an enclosing Batch captures it. Already started parallel operations continue.
The following sequence is a fragment. Replace ... with the omitted configuration before execution.
Code
Output
The Respond step does not add data to context. Instead, it returns an HTTP response to the workflow caller.
Examples
These examples are steps to include in the steps array of an execution request. Supply referenced variables such as currentTimestamp, requestId, and processingTime in context; they are not injected automatically.
Simple success response
Code
Response with dynamic data
Code
Created resource response
Code
Error response - not found
Code
Error response - validation error
Code
Conditional responses with Rule
Code
Response with custom headers
Code
Paginated response
Provide hasNext as a boolean in context, calculated by your caller or an earlier processing step. Morpher does not evaluate arithmetic or comparisons.
Code
Webhook acknowledgment
Code
AI analysis result
Code
Batch processing results
This example assumes processed_items is an array of records with a boolean success field. A Map step returns full iteration contexts, so adjust the field path to your nested output when using Map results.
Code
Common HTTP status codes
Success codes (2xx)
200- OK: Standard success response201- Created: Resource successfully created202- Accepted: Request accepted for processing204- No Content: Success with no response body
Client error codes (4xx)
400- Bad Request: Invalid input or malformed request401- Unauthorized: Authentication required403- Forbidden: Insufficient permissions404- Not Found: Resource does not exist422- Unprocessable Entity: Validation failed429- Too Many Requests: Rate limit exceeded
Server error codes (5xx)
500- Internal Server Error: Unexpected server error502- Bad Gateway: Upstream service error503- Service Unavailable: Service temporarily down504- Gateway Timeout: Upstream timeout
Best practices
Response structure consistency
Use a consistent response structure across your API:
Code
Status code selection
- Use appropriate status codes that match the HTTP specification
2xxfor successful operations4xxfor client errors (bad input, not found, etc.)5xxfor server errors (unexpected failures)
Error information
Provide helpful error information:
Code
Security considerations
- Don't expose sensitive internal information in error messages
- Avoid stack traces or system details in production
- Use generic messages for security-related errors
- Sanitize user input before including in responses
Performance headers
Include useful metadata headers:
Code
Common use cases
- API endpoints: Return structured responses for REST APIs
- Webhooks: Acknowledge receipt after any preceding steps complete
- Validation errors: Return detailed validation failures early
- Rate limiting: Return 429 when limits exceeded
- Authorization: Return 401/403 for auth failures
- Resource creation: Return 201 with Location header
- Not found: Return 404 when resources don't exist
- Early termination: Stop processing and respond on certain conditions
- Error handling: Return an error for a known condition or a failure captured as data
Workflow patterns
Early validation
Code
Success after processing
This is an incomplete sequence outline. Replace ... in the Request and Agent steps with their config objects, including the API URL and model settings, before execution.
Code
Conditional response
Request rejects HTTP error responses, so this rule runs only after a successful request. Its fallback selects a response for other successful HTTP statuses; it cannot catch a failed request. Use a Batch with failFast: false to collect request failures as data.
This is an incomplete sequence outline. Replace the Request step's ... with its config object, and replace both {...} placeholders with response bodies before execution.
Code
Troubleshooting
Templates not resolving
- Verify the context variable path is correct
- Check that previous steps have completed successfully
- Ensure the output name matches what you're referencing
- Use
{{ path }}and supported helpers. A sole template preserves the value's type; embedded templates produce strings.
Wrong status code sent
- Verify status code is within valid range (100-599)
- Set a numeric status in configuration; the status field is not templated
- Ensure no other respond steps execute before this one
Missing response data
- Confirm all referenced context variables exist
- Check that steps producing the data completed
- Verify template paths use correct dot notation
Headers not applied
- Ensure headers object is properly formatted
- Check for typos in header names
- Verify header values are valid strings