Skip to content

Robust PDF and DOCX Text Parsing in FastAPI Backend #3

Description

@Sumedh-6504

Description

Implement robust binary file parsing in the Python FastAPI backend (backend/parser.py) so that users can upload actual PDF and DOCX files, not just raw text.

User Story

As a LexGuard user,
I want to drop a .pdf or .docx contract into the upload pane,
So that I don't have to manually open, copy, and paste text.

Technical Tasks

  • Add standard Python parsing libraries pdfplumber and python-docx to backend/requirements.txt.
  • Update /parse route in backend/main.py to handle binary streams under UploadFile.
  • Implement secure text extraction in backend/parser.py:
    • Handle multi-page layouts, headers, and footers.
    • Reject corrupted or scanned-only PDFs (return a user-friendly error).
  • Sanitize extracted text to strip unnecessary control codes or empty lines before passing to the Detective agent.

Activity

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions