Skip to Content
API ReferencePOST /api/spot-check

POST /api/spot-check

Re-runs the spot-check audit on an already-extracted job without re-running extraction. Useful when you want to re-validate extraction accuracy after a pipeline update or to get a fresh confidence score.

Request

{ "job_id": "uuid-string" }

Headers: Authorization: Bearer <token>

Max duration: 120 seconds (Vercel serverless timeout)

Prerequisites

The job must have an output_storage_path (i.e., /api/extract must have completed successfully). If there is no output file, the endpoint returns a 400 error.

Processing Steps

  1. Authenticate via checkAuth()
  2. Fetch job and verify it has an output file
  3. Download original file from Supabase Storage and parse into CellGrid
  4. Download output file and read extracted rows from the Rent Roll sheet via XLSX parser
  5. Run spot-check — call spotCheckExtraction() to independently re-extract a sample of units and compare against the existing output
  6. Update job — merge new spot-check results into structure_result and update warnings

Job Updates

The following are updated on the job row:

  • structure_result._spot_check_confidence — new confidence score
  • structure_result._spot_check_discrepancies — new discrepancy list
  • warnings — old spot-check warnings are removed and replaced if confidence < 50
  • warning_count — recalculated from updated warnings array

Response

Success (200):

{ "job_id": "uuid-string", "spot_check_confidence": 92, "discrepancies": 1, "sample_size": 8 }
FieldTypeDescription
job_idstringThe job UUID
spot_check_confidencenumber0–100 confidence score from the audit
discrepanciesnumberCount of discrepancies found (not the full discrepancy objects)
sample_sizenumberNumber of units sampled for the audit

Validation Errors

CheckStatusMessage
Missing job_id400Missing job_id
Job not found500Error message from database or "Job not found"
No output file400No output file — run extraction first
No rows in output400No rows in output file
Missing Rent Roll sheet500Output file missing 'Rent Roll' sheet
Bad/missing token401Unauthorized

Error (500):

{ "error": "Something went wrong. Please try again." }

Notes

  • This endpoint does not re-run extraction. It reads the existing output file and re-audits a sample against the source spreadsheet.
  • The spot-check warning threshold is confidence < 50. If the new confidence is >= 50, any previous spot-check warning is removed.
  • Error messages are sanitized before returning to the client (same sanitization as /api/extract).
Last updated on