An API error contract for AI workflow integrations should tell the caller what happened and give it enough structured evidence to choose a safe next step. Use the HTTP status for the general outcome and a stable problem type for the specific condition. Map that type to a workflow action in code. A missing field calls for a correction. A temporary outage may warrant a retry. A business decision stays with the person authorized to make it.
Illustrative scenario. A support assistant extracts refund details from a ticket and proposes a request. A workflow service validates the proposal, checks the order and approval state, and submits eligible refunds. The order reference may be absent from the proposal, the order service may be temporarily unavailable, or the refund case may be awaiting a supervisor’s decision. From the assistant’s point of view, all three stop the refund. The workflow needs three different responses because each has a different owner and a different condition for resuming.
Define each problem by what lets work resume
RFC 9457 defines the JSON media type application/problem+json. The type URI identifies the problem class. title summarizes it for people, detail explains the occurrence, and instance can identify that occurrence. If you include status in the body, the origin sends the same code in the HTTP response. The body value is advisory. Document each type, its HTTP status, and any extension the caller needs. Use an absolute URI you control and keep it stable when the wording changes. RFC 9457, Problem Details for HTTP APIs
The following contract is for the illustrative refund submission endpoint. Each type name in the table is the final segment of an absolute URI under https://refunds.example.com/problems/.
| Response and problem type | What the service has established | What the workflow does |
|---|---|---|
422 · missing-refund-data |
The JSON is readable, and a required value is missing from the proposal. | Hold the request. Ask the support agent to supply the named field from an authorized record. Resume validation with the corrected proposal. |
503 · order-lookup-unavailable |
A temporary failure blocked the prerequisite lookup. This endpoint checks the order before initiating any refund. | Schedule another attempt within the retry budget. Wait at least as long as a valid Retry-After asks. Escalate if the budget is spent or the wait would exceed the deadline. |
409 · refund-approval-required |
Submission conflicts with the refund case’s current state, which is awaiting approval. | Hold the submission and attach the existing review reference. Resume when the approval system records a valid decision for this version of the proposal. Close the request if the approver declines. |
These statuses describe this endpoint’s behavior. The same 409 could mean the caller worked from an old revision. Its problem type would call for loading the current state and checking the proposal again. If the API’s job is to create a review request and it does so successfully, return a success response with the review resource and its pending state. Use problem details at the submission step when the pending state blocks the requested action. RFC 9110, HTTP Semantics
Make the response readable by code and by people
An illustrative rejection before any refund is submitted:
HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json
{
"type": "https://refunds.example.com/problems/missing-refund-data",
"title": "Required refund data is missing",
"status": 422,
"detail": "Add the order reference from the support record before submitting this refund.",
"instance": "/problem-occurrences/ex-missing-order",
"missing_fields": ["order_reference"]
}
Here missing_fields is an extension of this problem type. Define its value as a list of allowed request field names and document when the producer supplies it. A client can highlight the relevant field without parsing English prose. Localizing the title or changing the sentence in detail leaves the route intact. Ignore unrecognized extensions. If the information a specific route requires is absent or invalid, hold the work for inspection. Keep the instance reference opaque and record sensitive diagnostics separately under the service’s access controls. RFC 9457, sections 3–5
Key routing on the endpoint, actual HTTP status, and recognized type URI. Use values from the API response through a typed adapter. A model can draft an explanation from approved fields. The adapter and workflow policy decide whether a retry, a request for data, or an approval check is allowed. Keep stack traces, customer text, and raw upstream errors out of the response. A type URI identifies the problem and can point to documentation. The runtime can match it locally without fetching it. RFC 9457, sections 3 and 5
Treat an unknown write outcome as its own case
A known 503 from the refund service in the table comes from a path that exits before any refund is initiated. A timeout after submitting a refund has different consequences. The payment system may have applied the refund and lost the reply. A proxy might return HTML, or there may be no HTTP response at all. The caller should record an unknown outcome and reconcile it with the system that owns the write. Where the endpoint provides durable idempotency, reuse the same operation key and payload for an authorized retry. If the result cannot be established and repeating the write could issue another refund, hold the case for investigation. Retry-After supplies timing guidance for eligible retries. The endpoint contract and known write state determine eligibility. RFC 9110, idempotency · RFC 9110, Retry-After
Document a fallback for an unknown type, a mismatched status and body, or an unexpected content type. Keep the actual status and a correlation reference. Hold progression and reconcile any write whose outcome is uncertain. If the order provider uses its own error format, translate only the cases the adapter understands. A failed lookup cannot establish that an order reference is missing, and an unrecognized rejection cannot establish that a supervisor needs to approve it.
Give each stopped request an owner
A known business block should become a durable work item with an owner and a resume condition. The support agent can supply a missing reference. A supervisor can decide a refund. In either case, persist the handoff before acknowledging an asynchronous job, and key it so repeat deliveries reuse the same work item. A change to the proposal after review should trigger validation and any approval required for the new revision.
Use a dead-letter path for technical jobs that cannot be safely retried or have exhausted their delivery allowance. Amazon SQS can move an unsuccessfully processed message to a configured dead-letter queue based on maxReceiveCount. That policy counts receives. If the response establishes that further attempts are unsafe, the worker can record a durable dead-letter disposition and acknowledge the message immediately. Give the integration owner an operation reference, the failed step, the last recognized problem type or fallback reason, and any unresolved write state. That is enough to find the evidence before considering replay. AWS, Using dead-letter queues in Amazon SQS · Insonl, Dead-Letter Queue for ERP Integrations: Recovery
Test the action each response can trigger
Test each problem response at the API boundary and assert the resulting workflow state. Change or translate detail and verify the route stays the same. Send an unknown type, omit a required extension, and return a proxy error without a problem body. Check that none advances the refund. Simulate a write that commits before the connection drops and check that reconciliation or a same-key retry leaves a single refund. Deliver the approval-blocked job twice and check that the supervisor sees one work item. Change the proposal after approval and verify the original approval cannot release the new version.
Keep a separate review of successful actions. A correctly routed API rejection tells you that the failure path worked. Sampling completed refunds can show whether the workflow applied the right policy to requests that passed. Insonl, Sample AI-Approved Work for Errors Your Exception Queue Misses
Sources
- Defines the problem details media type, members, extensions, and disclosure considerations. RFC 9457, Problem Details for HTTP APIs
- Defines HTTP status semantics, idempotency, and
Retry-After. RFC 9110, HTTP Semantics - Explains dead-letter queues and the receive count in an SQS redrive policy. AWS, Using dead-letter queues in Amazon SQS
- Covers queue configuration, failure context, and redrive for failed ERP imports. Insonl, Dead-Letter Queue for ERP Integrations: Recovery
- Covers sampling completed automatic actions for errors that escape exception handling. Insonl, Sample AI-Approved Work for Errors Your Exception Queue Misses
- Describes Insonl’s generative AI services. Insonl, Generative AI
- Describes the workflow audit and how to request it. Insonl, Free AI workflow audit
Request an audit for one workflow
Bring an integration that stops on an ambiguous error, the responses it receives, and a description of what the workflow can write. Insonl can trace where the workflow should ask for data, retry, reconcile a write, or wait for an authorized decision. The audit is free. Insonl charges for follow-on work you choose to commission. Request a free AI workflow audit