> ## Documentation Index
> Fetch the complete documentation index at: https://docs.filerouter.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Inspect Document MIME Types Before Parsing

> Use inspectDocument() from @file_router/sdk/inspect to check a file's MIME type and detect binary-signature mismatches — entirely locally, before parsing.

`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

```ts inspect-import.ts theme={null}
import { inspectDocument } from '@file_router/sdk/inspect'
```

## 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. `.pdf` → `application/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

<ResponseField name="kind" type="'bytes' | 'url'">
  Whether the input was resolved as local bytes or as a URL.
</ResponseField>

<ResponseField name="name" type="string">
  The normalized filename resolved from the input (e.g. `'report.pdf'`). For URLs, this is derived from the last path segment.
</ResponseField>

<ResponseField name="resolvedMimeType" type="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`.
</ResponseField>

<ResponseField name="extensionMimeType" type="string">
  The MIME type inferred from the filename extension alone. Absent when the extension is unrecognized or generic.
</ResponseField>

<ResponseField name="detected" type="object">
  Present only for local files. Contains the MIME type and file extension identified from the file's binary signature.

  <Expandable title="detected fields">
    <ResponseField name="detected.mimeType" type="string">
      The MIME type identified from the binary signature (e.g. `'application/pdf'`).
    </ResponseField>

    <ResponseField name="detected.extension" type="string">
      The file extension corresponding to the detected binary format (e.g. `'pdf'`).
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="mismatch" type="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.
</ResponseField>

<ResponseField name="size" type="number">
  The byte size of the file. Present only for local file inputs, not for URLs.
</ResponseField>

## Example: inspect a local PDF

```ts inspect-pdf.ts theme={null}
import { inspectDocument } from '@file_router/sdk/inspect'

const inspection = await inspectDocument('./documents/report.pdf')

console.log('Name:', inspection.name)
console.log('Resolved MIME:', inspection.resolvedMimeType)
console.log('Detected:', inspection.detected)
console.log('Size:', inspection.size, 'bytes')

if (inspection.mismatch) {
  console.warn(
    `MIME mismatch! Extension says "${inspection.extensionMimeType}" ` +
    `but binary signature says "${inspection.detected?.mimeType}"`
  )
}
```

## Example: inspect a URL

```ts inspect-url.ts theme={null}
import { inspectDocument } from '@file_router/sdk/inspect'

// URLs are never fetched — only the path is examined
const inspection = await inspectDocument('https://example.com/contract.pdf')

console.log('Kind:', inspection.kind)       // 'url'
console.log('Name:', inspection.name)       // 'contract.pdf'
console.log('MIME:', inspection.resolvedMimeType) // 'application/pdf'
// inspection.detected is undefined for URLs
// inspection.mismatch is always false for URLs
```

<Note>
  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.
</Note>

<Tip>
  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.
</Tip>
