arrow_back Back to Legal Legal Ops Automation

Automated Contract Filing

The Context / Challenge

Setting the scene

Once a contract is fully executed, someone has to download the signed PDF, rename it, navigate to the right folder, and file it, then confirm the filing on the ticket or email thread. Contracts arrive from multiple sources (Jira tickets, DocuSign emails, forwarded PDFs) and the manual work is identical for each.

For teams processing dozens of contracts weekly, this leads to unfiled documents, inconsistent naming, duplicate folders, and no audit trail.

Our Approach

Two scripts, one vault

Two Google Apps Scripts share a single filing vault, naming convention, and AI-powered routing engine. No servers required. Everything runs on timed triggers.

Jira Auto-Filer

Runs every 15 minutes. Scans open legal tickets, identifies executed PDFs by filename keywords or comment triggers, OCRs the document, extracts metadata via AI (with regex fallback), renames and routes the file, and posts a confirmation comment.

Email Auto-Filer

Runs every 15-60 minutes. Monitors Gmail for DocuSign completion emails (sender-whitelisted) and PDFs forwarded to a dedicated filing inbox. Sends the raw PDF to an AI multimodal API for visual analysis, files it, and replies on the original thread with a Drive link.

Key design principles

01
AI-first with deterministic fallback. AI handles the happy path. Regex catches everything if the AI is unavailable or low-confidence.
02
Human-in-the-loop. Low-confidence decisions are flagged via @mentions (Jira) or warning rows (email). Never silently filed.
03
Fuzzy matching. Name normalization and scoring prevent duplicate client folders from accumulating over time.
04
Content-aware guards. NDA keywords match in subject/filename only, not in body text, to avoid false triggers from confidentiality clauses.
How to replicate this

Step by step

1

Define your filing taxonomy

Map top-level folders by agreement category (Advertiser, Partner, Vendor, NDA, Referral), with subfolders by region then client. Set a naming convention.

2

Build the Jira filer

Create an Apps Script with a Jira API token. Configure project key, monitored statuses, and custom field IDs. Track filed attachments per-ticket to prevent duplicates.

3

Build the email filer

Add a Gmail search for DocuSign completion emails filtered by sender whitelist. Label processed threads to avoid re-scanning.

4

Add AI metadata extraction

OCR each PDF, send to AI for client name, agreement type, signature date, and region. Include a regex/keyword fallback.

5

Implement folder routing with fuzzy matching

Map agreement types to folders with priority-ordered keywords. Normalize folder names before creating subfolders to prevent near-duplicates.

6

Add notifications and deploy

Post confirmation comments with filename, path, Drive link, and confidence warnings. Set timed triggers with retry logic.

Results

What we achieved

Eliminated repetitive contract filing work while maintaining permission safeguards. Contracts from both Jira and DocuSign emails are automatically classified, renamed, filed to the correct Drive folder, and confirmed back to the source. Filing errors dropped to near zero. The team reclaimed significant time for higher-value legal work.

Watch the demo

Video walkthrough

Watch video