AI Review Queue
Generated legal work must not silently mutate case records, final documents, portal updates, or outbound communications. Use the AI review queue to put generated work in a pending state until an authorized reviewer approves it.
Storage
Current implementation stores queue records in Firm.settings.aiReviewQueue.requests. This avoids a launch-blocking migration and keeps all records firm-scoped. The helper API is isolated in src/lib/ai/review-queue.ts so the queue can later move to a first-class table without changing route callers.
Required Flow
- Generate AI output and return the shared
aienvelope. - Call
createAIReviewRequest()for high-risk targets. - Return
review.requestIdto the UI. - Keep generated work in a pending/reviewing state.
- Approve, reject, request changes, or mark applied through
POST /api/ai/review-queue. - Only final mutation/send/publish paths should proceed after approval.
Target Types
outbound_communication: AI email, letter, SMS, or portal message drafts.document: demand letters, motions, briefs, settlement memos, discovery responses, and other legal documents.case_metadata: AI analysis that would become case truth, such as medical analysis or settlement recommendations.case_record: direct changes to primary case fields.portal_update: client-visible generated updates.workflow_action: generated automation actions.
Current Adoption
- AI communication drafts create
outbound_communicationreview requests. - AI document generation creates
documentreview requests for new and regenerated jobs. - AI document approve/reject/revision actions update the central queue decision trail.
- Medical-record analysis writes to
medicalAnalysisPendingReviewand creates acase_metadatareview request instead of replacing finalmedicalAnalysis.
API
GET /api/ai/review-queue: list firm-scoped requests with optionalstatus,targetType,caseId, andlimitfilters.POST /api/ai/review-queuewithaction=create: create a request for generated work.POST /api/ai/review-queuewithaction=approve,reject,request_changes, ormark_applied: record reviewer decisions.
Only ADMIN, ATTORNEY, and SUPER_ADMIN can approve or reject. PARALEGAL can view and create review items but cannot approve them.