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
| Setting | Key | Default | What it does |
|---|---|---|---|
| Inspect | operation | all | all (type, checksum, counts, and a search when Search for is set), detect (file type only), checksum, stats (counts and reading time) or search |
| Algorithms | algorithms | ["sha256"] | checksum and all: any of sha256, sha512, sha1, md5 |
| Search for | query | — (required for search) | Text, or a regular expression with Regular expression |
| Whole words | whole_word | false | Match whole words only (letters and digits around the match end it) |
| Match case | case_sensitive | false | |
| Regular expression | regex | false | Treat Search for as a regular expression (ReDoS-guarded) |
| Context characters | context_chars | 60 | Characters before and after each match (0–500) |
| Pages, sheet, OCR | pages, sheet, ocr, ocr_languages | all, all, off, eng | How the text is read, as in Read Document (not shown in the designer) |
| Output variable | output_var | inspection |
Outputs
| Variable | Contents |
|---|---|
{{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":
{
"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_mismatchis true when the name says one type and the content another — here a Word document named.pdf.detected_byiscontent, orextensionwhen the content gave no clue.statsandmetadataare the same as Read Document's; withall, 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, itspagefor PDFs, the textbeforeandafterit, and a one-linecontext. At most 500 matches are listed (truncated), butcountcounts them all.
The run history shows the essentials:
{ "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
statsandsearchfollows the read limits;detectandchecksumonly need the bytes, withinDOCUMENT_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
{
"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
searchon the redacted copy to confirm a term is gone.