generated from john/python-template
3.8 KiB
3.8 KiB
Error Handling Policy (Version 2)
This document defines the canonical error-handling policy for the V2 document transcription system.
Error Handling Objectives
- Make failures visible in clear, actionable language at both the document and individual page levels.
- Support isolated failure handling in multi-image batches so single page errors do not crash an entire batch job.
- Preserve diagnostic detail (Pydantic validation errors, raw provider responses) in PostgreSQL
JSONBfor fast troubleshooting. - Ensure consistent error envelope structure across API, UI, and async worker boundaries.
Scope And Authority
Governs error behavior across NiceGUI pages, FastAPI routes, service orchestration, asyncio background tasks, PostgreSQL interactions, and AI provider adapters.
Error Taxonomy
| Category | Definition | Retriable |
|---|---|---|
validation_error |
Pydantic payload or parameter schema validation failure | no |
user_input_error |
Unacceptable user file (unsupported image type, corrupt file) | no |
not_found_error |
Requested resource (Document, Source, Person, Job) missing |
no |
conflict_error |
Operation violates state constraints (e.g., duplicate document_person role) |
no |
external_provider_error |
AI Provider API failure (rate limit, vision execution error) | yes |
infrastructure_transient_error |
Temporary DB connection reset or HTTP timeout | yes |
infrastructure_persistent_error |
Database down, missing API credentials, misconfiguration | no |
internal_unexpected_error |
Uncaught Python exception or logic defect | no |
Async Batch & Page-Level Error Behavior
In multi-image asyncio batch processing:
- Page Isolation: Exceptions caught during individual page calls are caught within the
asynciotask wrapper. - Page Record Logging: Page failure detail is written directly to
job_source.error_detailandjob_source.status = 'failed'. - Batch Aggregate State:
- If all page tasks succeed ->
job.status = 'completed'. - If some page tasks fail ->
job.status = 'partial_success'. - If all page tasks fail ->
job.status = 'failed'.
- Retry Strategy: The UI exposes a "Retry Failed Pages" option for
partial_successjobs, which spawns a new targetedJobcontaining only theSourceIDs marked asfailed.
API Error Response Contract
API error responses return a structured JSON envelope:
{
"error_id": "err_uuid_12345",
"category": "validation_error",
"message": "The uploaded payload failed schema validation.",
"suggestion": "Check file format and metadata fields, then try again.",
"details": {
"pydantic_errors": [...]
},
"timestamp": "2026-07-31T07:55:00Z"
}
HTTP Status Mappings:
validation_error,user_input_error->400not_found_error->404conflict_error->409external_provider_error->502/503infrastructure_transient_error->503infrastructure_persistent_error,internal_unexpected_error->500
Technology References
- FastAPI documentation
- NiceGUI documentation
- PostgreSQL documentation
- Python asyncio
- Pydantic Validation
- Pydantic AI
Related Local References
- System Overview
- System Design Intent
- Transcription Methodology
- System Architecture
- System Requirements
- Data model
- Error Handling Policy (this document)
- Implementation Plan