Skip to content

Fix: Bedrock aspect ratio rejection for form PDFs#45

Open
Nishit24113 wants to merge 1 commit intomainfrom
fix/bedrock-aspect-ratio-validation
Open

Fix: Bedrock aspect ratio rejection for form PDFs#45
Nishit24113 wants to merge 1 commit intomainfrom
fix/bedrock-aspect-ratio-validation

Conversation

@Nishit24113
Copy link
Copy Markdown
Collaborator

Summary

  • Form PDFs (court forms, license forms, etc.) contain thin decorative elements (underlines, borders, separators) that Adobe AutoTag extracts as images
  • These images have extreme aspect ratios (e.g., 500px wide x 2px tall = 250:1)
  • Bedrock API rejects any image with aspect ratio > 20:1
  • When ALL images fail, the job crashes via process.exit(1) and Step Function retries indefinitely — user sees it stuck for 60+ minutes

Changes (1 file, no new dependencies)

  • Added getImageDimensions() — reads PNG/JPEG headers to get width/height
  • Added isAspectRatioValid() — checks against Bedrock's 20:1 limit
  • Before sending each image to Bedrock, checks aspect ratio. If > 20:1, skips it and assigns "Decorative element" as alt text
  • Updated failure condition: only process.exit(1) if all images failed AND none were skipped

Test plan

  • Upload a form PDF with thin horizontal lines (e.g., Form_Example_2.pdf)
  • Verify job completes instead of failing
  • Verify skipped images get "Decorative element" alt text
  • Verify normal images still get AI-generated alt text
  • Check CloudWatch logs for skip messages with dimensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant