AI Contract Redline: Compare Signed Documents Against Originals
Automatically redline any signed contract or agreement against its original and produce an exhaustive change report before counter-signing. Upload the returned signed document (PDF, DOCX, or scanned image), name the original stored in Google Drive (DOCX or native Google Doc), and the workflow OCRs the signed copy, locates and downloads the original from Drive, converts both to clean text, and surfaces every difference categorized by type: substantive wording and clause changes with section numbers and side-by-side quotes, filled-in fields such as parties, effective dates, dollar amounts, addresses, and signer names and titles, signature block label differences, DocuSign and other e-signature artifacts, OCR rendering artifacts to ignore, and shared typos worth fixing in the original. Built for legal contract review, NDA comparison, MSA and SOW intake, vendor agreement onboarding, employment offer letter audits, partnership and referral agreement review, sales contract redlining, real estate purchase agreement comparison, insurance policy diff, lease and rental agreement review, and any returned-document intake workflow where you need to know exactly what changed before filing or counter-signing. Eliminates manual side-by-side reading, accelerates legal and operations review cycles, and prevents accidental acceptance of unfavorable revisions hidden inside a returned signed document.
Collect Inputs
Goal: Confirm the two documents the user wants to compare: the signed/returned document and the original. | Inputs: User chat message and any uploaded files. The signed document may be referenced by File Management file_id (if uploaded earlier) or attached as a chat upload. The original is identified by a Google Drive name (preferred) or document ID. | Outputs: Two values: (1) signed_file_id - File Management file_id for the signed document; (2) original_query - the exact Drive search string for the original (file name including extension if known). | Constraints: If the user has not uploaded a signed document, ask them to upload it before continuing. If the user has not named the original, ask explicitly. Do not proceed until both values are known. Never invent file_ids or original names. | Success criteria: Both signed_file_id and original_query are captured and confirmed back to the user before continuing.
OCR Signed Document
Pass the signed_file_id from the previous step as file_ids: [signed_file_id]. Extract plain text only - we do not need entities or per-page metadata for the diff. Preserve the full text in the output for downstream comparison.

Find Original in Drive
Pass the original_query from gather-inputs as the query parameter. If multiple results match, prefer the most recently modified file owned by the user. If zero results, surface this to the user before continuing - do not fabricate a file_id.

Workflow preview
What the agent will follow (tools, prompts, and workflow steps).
1. Apply the following prompt: Goal:
Confirm the two documents the user wants to compare: the signed/returned document and the original.
Inputs:
User chat message and any uploaded files. The signed document may be referenced by File Management file_id (if uploaded earlier) or attached as a chat upload. The original is identified by a Google Drive name (preferred) or document ID.
Outputs:
Two values: (1) signed_file_id - File Management file_id for the signed document; (2) original_query - the exact Drive search string for the original (file name including extension if known).
Constraints:
If the user has not uploaded a signed document, ask them to upload it before continuing. If the user has not named the original, ask explicitly. Do not proceed until both values are known. Never invent file_ids or original names.
Success criteria:
Both signed_file_id and original_query are captured and confirmed back to the user before continuing.
2. Call tool: Document OCR Agent (OCR Signed Document).
Instructions:
Pass the signed_file_id from the previous step as file_ids: [signed_file_id]. Extract plain text only - we do not need entities or per-page metadata for the diff. Preserve the full text in the output for downstream comparison.
Parameters:
{"action": "process_document", "document_type": "general", "include_pages": false, "include_entities": false, "max_text_chars": 100000}
3. Call tool: Google Drive (Find Original in Drive).
Instructions:
Pass the original_query from gather-inputs as the query parameter. If multiple results match, prefer the most recently modified file owned by the user. If zero results, surface this to the user before continuing - do not fabricate a file_id.
Parameters:
{"action": "search_files", "page_size": 10}
4. Call tool: Google Drive (Download Original).
Instructions:
Use the chosen file's id from find-original as file_id. For native Google Docs add export_format: "txt". For DOCX/PDF/other binary files omit export_format - the download produces a signed URL we will pass to MarkItDown next.
Parameters:
{"action": "download_file_to_storage"}
5. Call tool: MarkItDown Hosted Markdown Generator (Extract Original Text).
Instructions:
Pass the signed_url from download-original as the url parameter. MarkItDown returns the original as Markdown text we can diff against the OCR output. Preserve the full markdown in the output for downstream comparison.
Parameters:
{"action": "convert"}
6. Apply the following prompt: Goal:
Produce an exhaustive, accurate list of every difference between the OCR'd signed document text and the original markdown.
Inputs:
1) Plain text from ocr-signed-doc (the signed document). 2) Markdown from extract-original-text (the original). Both cover the same agreement type.
Outputs:
A categorized diff with these buckets, each populated only if there are findings: (a) Substantive wording changes - any sentence/clause where the legal meaning differs, with the section number, the original wording, and the signed wording quoted side-by-side. (b) Filled-in fields - blanks in the original that have content in the signed copy (parties, dates, addresses, dollar amounts, signature names/titles). (c) Signature block differences - changes in headers, labels, or 'Title (if applicable)' style wording. (d) Signing artifacts - DocuSign envelope IDs, signature stamps, page footers introduced by the e-sign platform. (e) OCR-likely artifacts - apparent differences (such as list lettering schemes a-z vs 1-3 per section) that are most likely OCR rendering, flagged so they are not treated as real changes. (f) Typos or errors present in both - flagged so they can be corrected in the original.
Constraints:
Cite section numbers when available. Quote the exact wording from each side - do not paraphrase substantive changes. Do not invent differences. If a section is identical, do not list it. Section numbering schemes between OCR and DOCX may differ purely because of formatting - check item counts before flagging numbering as substantive.
Success criteria:
Every substantive wording change is listed with both versions quoted. No identical text is mistakenly flagged as a difference. The user can act on the report without re-reading either document.
7. Apply the following prompt: Goal:
Return the diff report to the user as the final assistant message, formatted for quick legal review.
Inputs:
The categorized diff from compare-documents.
Outputs:
A single Markdown response that opens with a one-sentence headline (e.g. 'One substantive change to flag plus N filled-in fields'), followed by the categorized buckets as Markdown tables where comparing two versions, and bullet lists for one-sided items. End with a short recommended action (sign as-is, request revision, escalate to legal).
Constraints:
Do not include any text the user already saw in the inputs verbatim - only the structured report. Keep the headline accurate to the actual findings. Do not add emojis.
Success criteria:
The user can read the report once and decide whether to counter-sign, request changes, or escalate.




