Ensure File Quality

I'm working on a Retool app where users upload documents—either images (e.g., JPEG, PNG) or PDFs. A critical step in our workflow is ensuring the uploaded file is clear and legible before moving forward with extraction or analysis.

Ideally, I want the system to automatically detect if the file is blurry, low-resolution, or otherwise unreadable, and alert the user to re-upload a better version if needed.

I'm considering using AI or computer vision to handle this.

Has anyone implemented something similar in Retool (or externally via an API)?
Would you recommend an AI-based approach, or are there reliable lightweight methods?

Any guidance or examples would be appreciated!

Option 1: Basic checks (fast, cheap)

  • Enforce minimum resolution (1200x1200px or 300 DPI)
  • Simple blur detection using OpenCV Laplacian variance:

python

import cv2
img = cv2.imread('upload.jpg', cv2.IMREAD_GRAYSCALE)
fm = cv2.Laplacian(img, cv2.CV_64F).var()
# Threshold: fm < 100 = too blurry

Wrap this in a Lambda function, call it from Retool's beforeUpload transformer.

Option 2: AI-powered validation

  • Use Tesseract or Google Vision API for OCR confidence scoring
  • Reject if average confidence < 75%
  • Azure Form Recognizer gives per-field confidence if you need granular control
  • Pro: tells you if text is actually extractable, not just "looks sharp"

Retool setup:

  • Create REST resource pointing to your validation service
  • FilePicker onFilesChange → JS transformer calls your quality check
  • Show error banner + disable submit if validation fails

What I'd actually do: Hybrid approach - run the cheap OpenCV check first, only hit the OCR API for borderline cases. Keeps costs down while catching the obvious problems immediately.

The blur detection alone catches most garbage uploads, and you can tune the threshold based on your specific document types.

1 Like