Defensive API Contract and Error Handling Review Framework
Audit external-facing service contracts, input validation, and failure-handling strategies for resilience.
Apply this prompt when reviewing new API endpoints or webhook consumers. It generates an actionable review framework to guarantee predictable error envelopes, input validation, and idempotent failure handling.
Role: Lead Platform Reliability Engineer specializing in resilient microservice interface design.
Context
- Endpoint name: {{api_endpoint_name}}
- Protocol type: {{protocol_type}}
- Consuming clients: {{client_consumers}}
- Code implementation: {{code_implementation}}
- Target availability SLA: {{sla_target}}
- Upstream retry policy: {{retry_policy}}
Task
Produce an API resilience and error handling review framework that audits {{api_endpoint_name}} for defensive contract enforcement, fault isolation, and safe retry behaviors in line with {{sla_target}}.
Method
- Parse {{code_implementation}} for boundary validation, payload bounds checking, and schema enforcement.
- Trace all upstream external calls to verify appropriate timeout and circuit breaking configurations.
- Audit error propagation logic to ensure internal exception traces never leak through the {{protocol_type}} interface.
- Evaluate idempotency mechanisms for mutating endpoints under repetitive requests matching {{retry_policy}}.
- Inspect status code mappings and structured error envelopes for consistency across {{client_consumers}}.
- Review fallback routines and partial degradation paths when downstream dependencies fail.
- Formulate defensive coding standards and error payload specifications for the endpoint.
Constraints
- MUST validate idempotency handling for all non-safe HTTP/RPC methods.
- MUST NOT permit raw database or runtime stack traces in public error envelopes.
- Recommendations must preserve compliance with {{sla_target}}.
- All error contracts must define structured machine-readable error codes.
Output format
- Contract Resilience Analysis (2 paragraphs)
- Error Handling Deficiency Matrix (Markdown table: Error Path, Current Behavior, Failure Risk, Defensive Standard)
- Standardized Error Envelope Schema (JSON/Schema definition)
- Client Resilience and Retry Guidance (Technical specification for {{client_consumers}})
Self-review
- Ensure input validation edge cases (e.g., payload size, malformed types) are addressed.
- Confirm error envelope masking conforms to security requirements for {{client_consumers}}.
- Check that idempotency controls withstand replay scenarios under {{retry_policy}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.