Documents

Inspect Document

Check a file's real type from its content, compute checksums, count words and characters, estimate reading time, and search the text with context.

Inspect Document (doc_inspect) answers questions about a file without converting it: what it really is (from its content, not its name), its checksums, how long it is, and where a word or pattern occurs.

Inputs

Document (source): a file object, a list (the first file), a storage:// reference, a URL, base64 content or text. See File inputs.

Options

SettingKeyDefaultWhat it does
Inspectoperationallall (type, checksum, counts, and a search when Search for is set), detect (file type only), checksum, stats (counts and reading time) or search
Algorithmsalgorithms["sha256"]checksum and all: any of sha256, sha512, sha1, md5
Search forquery— (required for search)Text, or a regular expression with Regular expression
Whole wordswhole_wordfalseMatch whole words only (letters and digits around the match end it)
Match casecase_sensitivefalse
Regular expressionregexfalseTreat Search for as a regular expression (ReDoS-guarded)
Context characterscontext_chars60Characters before and after each match (0–500)
Pages, sheet, OCRpages, sheet, ocr, ocr_languagesall, all, off, engHow the text is read, as in Read Document (not shown in the designer)
Output variableoutput_varinspection

Outputs

VariableContents
{{inspection}}The result (below); which parts are there depends on the operation
{{inspection_matches}}Search: the matches
{{inspection_match_count}}Search: the number of matches

A Word file uploaded as agreement.pdf, searched for the whole word "term":

{{inspection}}
{
  "file": { "name": "agreement.pdf", "size": 12840, "mime_type": "application/pdf" },
  "type": { "format": "docx", "mime_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "extension": "docx", "label": "Word document", "detected_by": "content", "is_text": false, "extension_mismatch": true },
  "checksums": { "sha256": "b1946ac92492d2347c6235b4d2611184e8c1b7a6f0d43e2b8f1c9a7d5e3b2a10" },
  "stats": { "words": 30, "characters": 196, "characters_no_spaces": 166, "lines": 8, "paragraphs": 1, "sentences": 7, "reading_time_minutes": 1, "pages": 2, "slides": null, "sheets": null },
  "metadata": { "title": "Supply Agreement", "author": "Andrew Fuller", "…": "…" },
  "search": {
    "query": "term",
    "count": 2,
    "matches": [
      { "text": "Term", "index": 78, "line": 3, "before": "xotic Liquids. See the terms.\n", "after": "\n- The term is 24 months.\n- Co", "context": "xotic Liquids. See the terms. Term - The term is 24 months. - Co" },
      { "text": "term", "index": 89, "line": 4, "before": "ds. See the terms.\nTerm\n- The ", "after": " is 24 months.\n- Contact: orde", "context": "ds. See the terms. Term - The term is 24 months. - Contact: orde" }
    ],
    "truncated": false
  }
}
  • type.extension_mismatch is true when the name says one type and the content another — here a Word document named .pdf. detected_by is content, or extension when the content gave no clue.
  • stats and metadata are the same as Read Document's; with all, a file that cannot be read (an image without OCR, an unsupported type) still gets its type and checksum, with a warning.
  • Each match has its line, its page for PDFs, the text before and after it, and a one-line context. At most 500 matches are listed (truncated), but count counts them all.

The run history shows the essentials:

json
{ "variable": "inspection", "format": "docx", "mime_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "extension_mismatch": true, "sha256": "b1946ac9…", "words": 30, "reading_time_minutes": 1, "matches": 2 }

On the canvas

The operation and output variable, or the search: all → inspection, Find "termination".

Limits

  • Reading for stats and search follows the read limits; detect and checksum only need the bytes, within DOCUMENT_MAX_MB.
  • A regular-expression search scans the first 2,000,000 characters of the text.
  • Reading time assumes 230 words a minute.

Security notes

The type is decided from the content (magic bytes, the parts inside a ZIP container, text sniffing), so a PDF named .docx or a spreadsheet named .pdf is recognised for what it is. Binary content that matches no known format falls back to the name's extension (detected_by: "extension"), so check format against what you expect rather than trusting the name. Regular expressions go through the ReDoS guard. See Security.

Example

json
{
  "type": "doc_inspect",
  "label": "Check upload",
  "config": {
    "source": "{{form.upload}}",
    "operation": "all",
    "algorithms": ["sha256", "md5"],
    "query": "termination",
    "whole_word": true,
    "context_chars": 80
  }
}

Canvas: all → inspection.

Works well with

  • A Condition on {{inspection.type.extension_mismatch}} or {{inspection.type.format}} to reject a file that is not what it claims.
  • A Data step that stores {{inspection.checksums.sha256}}, to spot the same file being submitted twice.
  • Redact Document, then a search on the redacted copy to confirm a term is gone.