What this prompt does
This prompt asks the AI to design an error handling and logging framework for your [framework] application. It defines a standard error response (status, code, message, details, request_id, docs_url), a custom exception hierarchy ([exception_types]), an error-code registry, structured logging in [log_format], correlation-ID propagation, request/response logging middleware with PII redaction, error-rate monitoring via [monitoring_tool], client-friendly versus internal messages, field-level validation errors, and auto-generated error docs — plus log aggregation, error-budget tracking, and on-call alerting rules.
The structure works because error handling is what makes an API debuggable at 2am, and it's almost always an afterthought. The consistent error envelope means every failure looks the same to clients. [exception_types] defines a hierarchy so each failure maps to the right status and code, [log_format] (like JSON structured) makes logs machine-queryable, and correlation IDs let you trace one request across services. Wiring [monitoring_tool] in from the start turns errors into alerts instead of silent failures.
When to use it
- You're building a backend and want consistent, debuggable errors from day one
- You need a custom exception hierarchy mapping
[exception_types]to status codes - You want structured logging in
[log_format]that your log platform can query - You need correlation IDs to trace a request across services
- You're wiring error-rate monitoring and alerting through
[monitoring_tool] - You need field-level validation errors and a documented error-code registry
Example output
Expect a framework design: the standard error envelope, an exception class hierarchy for [exception_types], an error-code registry table, logging middleware emitting [log_format] with PII redaction, correlation-ID propagation logic, and a monitoring/alerting section tied to [monitoring_tool]. It usually includes the distinction between client-safe and internal messages and a validation-error format with field-level detail.
Pro tips
- Match
[framework]to your real stack so the middleware and exception code is idiomatic, not generic - Build the error-code registry early; stable, documented codes are what let clients handle errors programmatically
- Insist on correlation-ID propagation across service boundaries — it's the single most useful debugging tool in distributed systems
- Keep client-facing messages clean while logging full internal detail; leaking stack traces to clients is a security risk
- Use structured
[log_format](JSON) so you can filter and alert on fields, not grep raw text - Don't skip PII redaction in the logging middleware; logging request bodies verbatim is how sensitive data ends up in your logs