Skip to main content
inspectDocument() from @file_router/sdk/inspect gives you a detailed picture of how FileRouter will classify a document before you send it to any provider. It runs entirely locally — it reads bytes from disk or memory and uses binary signature analysis to detect the real file type. No data is ever sent to a network endpoint during inspection.

Import

inspect-import.ts

How inspection works

When you pass a local file (a File, Blob, path string, or bytes), inspectDocument() performs three checks:
  1. Extension MIME type — infers the MIME type from the filename extension (e.g. .pdfapplication/pdf).
  2. Binary signature detection — reads the file’s magic bytes to identify the real format, independent of the filename.
  3. Mismatch detection — compares the resolved MIME type against the binary signature and sets mismatch: true if they conflict.
When you pass a URL, the URL is classified by its filename path only. URLs are never fetched — the function just parses the path segment and infers the MIME type from the extension.

DocumentInspection

kind
'bytes' | 'url'
Whether the input was resolved as local bytes or as a URL.
name
string
The normalized filename resolved from the input (e.g. 'report.pdf'). For URLs, this is derived from the last path segment.
resolvedMimeType
string
The MIME type FileRouter will use when sending this document to a provider. Determined by applying the MIME resolution order: explicit MIME → extension → application/octet-stream.
extensionMimeType
string
The MIME type inferred from the filename extension alone. Absent when the extension is unrecognized or generic.
detected
object
Present only for local files. Contains the MIME type and file extension identified from the file’s binary signature.
mismatch
boolean
true when the resolvedMimeType is specific (not application/octet-stream) and conflicts with the binary signature detected in the file. A mismatch often means a file has been renamed or has the wrong extension.
size
number
The byte size of the file. Present only for local file inputs, not for URLs.

Example: inspect a local PDF

inspect-pdf.ts

Example: inspect a URL

inspect-url.ts
Inspection is entirely optional. The FileRouter core router does not reject documents with unknown MIME types — text formats like CSV and Markdown do not have reliable binary signatures, and provider format support changes independently of FileRouter releases. Use inspectDocument() when you want to validate inputs or debug unexpected provider behavior.
Check inspection.mismatch before parsing if you’re processing user-uploaded files. A mismatch often indicates a renamed file (e.g. a JPEG saved with a .pdf extension), which can cause a provider to return an error or an empty result.