Skip to main content

K12 Database (Overview)

What this section is for

Use this section when you’re:

  • implementing or debugging K12 EOP workflows
  • implementing or debugging K12 QRG generation/editing
  • tracing a request from tool call → workflow run → stored result

This section is K12-focused by design.

For cross-cutting database topics (Core tables, agent prompt storage, etc.), see the Database tab:

  • /database/overview
  • /database/agents

Where K12 data lives

K12 workflow data is stored in Azure SQL under the K12SAFETY schema.

The schema has two “table families” most commonly encountered:

  • EOP request logging & monitoring

    • Optimized for auditing and operational timelines.
    • Documented in /k12/internal/database/eop.
  • QRG normalized storage

    • Optimized for querying and downstream consumption.
    • Documented in /k12/internal/database/qrg.

Source of truth for table definitions

  • Exhaustive schema model (DACPAC):
    • db/sqlproj/Mastra.Platform.K12SafetyDb/model/Tables/*
  • Seed scripts and K12-specific utilities:
    • db/k12/seed/

Quick verification

  • Verify connectivity + presence of key tables through the admin DB health tool:
    • POST /admin/tools/db-health-check
    • Operator/runtime route only. Replit/Admin UI browser flows should use local /admin-api/* or testing /dashboard/admin-api/*.

K12SAFETY schema architecture

The K12SAFETY schema contains two main table families:

EOP Tables (Logging & Monitoring)

  • log_EOP_TaskRequests - Request and response envelope
  • log_EOP_TaskStatus - Status timeline for monitoring
  • log_Jobs - Async execution state
  • log_EOP_TaskRequestSystemPrompts - Prompt override auditing
  • log_EOP_TaskRequestContext - Resolved snapshot, organization, and role context per request

See the EOP database page for the complete ER diagram and detailed documentation.

QRG Tables (Normalized Storage)

  • qrg_requests - Request envelope and status
  • qrg_generations - Generation metadata
  • qrg_generated_items - Individual QRG items
  • qrg_generation_annexes - Per-annex processing tracking (status, classification, extraction)
  • qrg_ai_calls - Individual AI call logs (prompt, response, tokens, duration)
  • qrg_execution_errors - Workflow-level error tracking
  • qrg_edits - Editing results
  • qrg_edit_context - Edit context snapshots (organization, role tags, QRG metadata)
  • qrg_request_prompts - Captured prompts
  • qrg_request_roles - Role/tag associations

See the QRG database page for the complete ER diagram and detailed documentation.

Views

  • vw_eop_request_traceability - Joins EOP request, status, job, and prompt data
  • vw_qrg_full_traceability - Full QRG request-to-result traceability
  • vw_qrg_input_output_trace - Annex input vs QRG output comparison
  • vw_qrg_ai_call_summary - AI call metrics per request
  • vw_qrg_annex_ai_details - Per-annex AI processing details
  • vw_qrg_error_summary - Joined error analysis with request/annex context
  • vw_qrg_edit_traceability - QRG edit request-to-result traceability

Table summary

TablePurposeKey columns
log_EOP_TaskRequestsEOP workflow task requests and responsesRequestID, TaskName, ResponseStatus
log_EOP_TaskStatusEOP task status timelineRequestID, Status, StatusMessage
log_JobsGeneral job logging for K12 workflowsrequest_id, job_type, status
log_EOP_TaskRequestSystemPromptsPrompt override auditingRequestID, PromptHash
log_EOP_TaskRequestContextResolved context (snapshot, org, roles)RequestID, ContextResolutionStatus
qrg_requestsParent table for QRG generation/editing requestsRequestId, RequestType, Status
qrg_generationsQRG generation metadata and resultsRequestId (FK), AnnexCount, QrgCount
qrg_generated_itemsIndividual generated QRG itemsRequestId (FK), QrgName, QrgType
qrg_generation_annexesPer-annex processing trackingRequestId (FK), AnnexId, ProcessingStatus
qrg_ai_callsIndividual AI call logsRequestId (FK), StepType, Status, TotalTokens
qrg_execution_errorsWorkflow-level error trackingRequestId (FK), ErrorType, FailedStep
qrg_editsQRG editing requests and resultsRequestId (FK), QrgName, Section
qrg_edit_contextEdit context snapshotsRequestID, ContextStatus
qrg_request_promptsCustom prompts for QRG requestsRequestId (FK), UserPrompt, SystemPromptHash
qrg_request_rolesUser roles associated with requestsRequestId (FK), RoleLabel, RoleTagId

Next pages

  • EOP tables: /k12/internal/database/eop
  • QRG tables: /k12/internal/database/qrg