CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/fastapi-error-handling

Production error handling for FastAPI — exception handlers, structured error

96

6.12x
Quality

96%

Does it follow best practices?

Impact

98%

6.12x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

criteria.jsonevals/scenario-2/

{
  "context": "Tests whether the agent proactively applies FastAPI error handling best practices when building an inventory API. The task describes business rules that naturally produce errors but says nothing about exception handlers, error response format, or validation error customization -- the agent should add these on its own.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "Custom exception classes for domain errors",
      "description": "Agent defines custom exception classes (e.g. NotFoundError, ConflictError, BusinessRuleError) rather than using bare HTTPException with string details everywhere. The agent was NOT asked to create exception classes.",
      "max_score": 12
    },
    {
      "name": "Exception handler for custom errors registered",
      "description": "Agent registers @app.exception_handler for custom exception types that returns a structured JSON error response. The agent was NOT asked to register exception handlers.",
      "max_score": 14
    },
    {
      "name": "RequestValidationError handler registered",
      "description": "Agent registers @app.exception_handler(RequestValidationError) to produce structured validation errors with field-level detail, replacing FastAPI's default 422 format. The agent was NOT asked to customize validation errors.",
      "max_score": 14
    },
    {
      "name": "Generic catch-all Exception handler",
      "description": "Agent registers @app.exception_handler(Exception) that returns a safe generic error message for unexpected errors, without leaking stack traces or internal details. The agent was NOT asked about catch-all handlers.",
      "max_score": 14
    },
    {
      "name": "Consistent structured error format across all routes",
      "description": "All error responses use the same JSON shape with at least a code/type and a message field. Business rule violations (insufficient stock, duplicate SKU), validation errors, and not-found errors all use the same structure.",
      "max_score": 12
    },
    {
      "name": "No internal details leaked",
      "description": "Error responses for unexpected server errors do not include Python tracebacks, file paths, or raw exception strings.",
      "max_score": 8
    },
    {
      "name": "Semantically correct HTTP status codes",
      "description": "Different error types map to correct status codes: 404 for product not found, 409 for duplicate SKU, 400/422 for invalid input (negative price, stock below zero), 500 for unexpected errors.",
      "max_score": 10
    },
    {
      "name": "Errors logged server-side",
      "description": "Unexpected errors are logged using Python's logging module, structlog, or similar before returning the safe generic response. The agent was NOT asked to add logging.",
      "max_score": 8
    },
    {
      "name": "Validation error field details",
      "description": "The custom RequestValidationError handler includes per-field error details (field name and what went wrong) rather than a single opaque error string.",
      "max_score": 8
    }
  ]
}

evals

tile.json