Document Upload Tools for AI Agents: Checks to Run First
Check file type, size and malware before an AI agent accepts a customer upload. A practical order of checks, rejections and approvals for operations teams.

An AI agent should not read, store or act on a customer document until it has passed three gates in order: a file type check based on the actual file content, a size limit set for that workflow, and a malware scan that runs in quarantine before any parser opens the file. Each gate rejects files with a clear reason and a log entry, so the agent only works with documents your own team would also accept. Extraction and any write action come after these checks, never before.
Key takeaways
- Check the real content of a file, not its name or extension.
- Set size and page limits per workflow, and refuse archives you cannot inspect.
- Scan for malware in quarantine before any parser or agent touches the file.
- Treat text inside a document as data to read, never as instructions the agent should follow.
- Log every verdict with a reason and a time, so rejections can be reviewed and tuned.
Why the upload step needs its own checks
When a business lets an agent receive documents, the upload is the first point where outside content enters company systems. A customer may send a purchase order, a signed contract, a scanned receipt or a spreadsheet, and any of them can be malformed, oversized, mislabeled or hostile. An agent that reads whatever arrives is, in practice, trusting the sender with the tools the agent holds.
The fix is not a more capable model. It is a plain gate that runs before the model sees anything. The OWASP Top 10 for LLM Applications treats untrusted input as a risk category in its own right, and document intake is one of the most common ways untrusted input reaches an agent. Teams that have already set up least privilege for AI agents will recognize the pattern: start narrow, and widen access only when the evidence supports it.
The order of checks before an agent accepts a file
Run these checks in sequence. A file that fails an early check never reaches a later one, which keeps the more expensive and riskier steps away from files that should never have been accepted in the first place.
- Confirm the upload arrived through an approved channel and belongs to a workflow that expects this kind of document.
- Detect the actual file type from its content and compare it with the types the workflow allows.
- Apply the file size, batch size and page limits defined for that workflow.
- Inspect archives inside an isolated step with strict limits on nesting and expanded size.
- Move the file into quarantine storage and scan it for malware there.
- Remove or refuse active content such as macros, embedded scripts and external links when the workflow does not need them.
- Parse the file in an isolated process with a time limit.
- Pass only the extracted fields, with a reference back to the source page, into the agent's working context.
- Write a verdict record containing a hash of the file, the check that decided, the reason and the time.
The last step is easy to skip and expensive to miss later. Without it, you cannot answer the question an auditor or a customer will eventually ask: why was this file accepted, and by which rule?
File type: check the content, not the extension
A file name is a label the sender chooses. A file called invoice.pdf can contain a spreadsheet, and a Word document can carry a macro inside a container that looks harmless from the outside. Real type detection reads the leading bytes and the internal structure of the file, then compares what it finds with the types the workflow accepts. Many formats have recognizable signatures, and container formats such as modern Office files need a second look at their contents, not only their outer label.
Build the allowlist from the workflow, not from the software you happen to have. If a supplier onboarding flow needs PDF files and two image formats, accept those and nothing else. Every additional format is another parser to maintain and another surface that can fail. When a file does not match, send a short message that names the expected types so the sender can resend correctly. Do not describe the detection logic, because that information helps the next attacker more than the next customer.
Scanned documents and photographs deserve their own rules. A file can be a perfectly valid image and still contain text the agent must treat as data. Before you decide what the agent extracts from a scan, read how OCR for AI agents handles reading accuracy and confidence, because a low confidence field should go to review rather than into a record.
A file that has the right name and the wrong content should be treated as the wrong file.
Illustrative scenario: a purchasing team forwards supplier documents to an intake address. One message contains a file named quote.pdf. The type check finds that its content is a macro-enabled workbook, so it is rejected before parsing. The supplier receives a request for a PDF export, the verdict is logged, and the purchasing lead sees the rejection in the daily summary. The agent never opens the workbook.
Size limits and archives
Size limits protect the parser, the storage and the agent's context. Set a limit per file, a limit for the total size of an upload batch and, for documents with pages, a maximum page count. Base the values on the largest legitimate document the workflow actually receives, add a margin, and review them once real traffic shows what normal uploads look like. A limit set from guesswork tends to either block valid work or leave the parser exposed.
Archives need stricter treatment than ordinary files. A compressed file can expand far beyond its upload size, and nested archives can hide content from a shallow inspection. A sound default is to refuse password-protected archives, refuse nesting beyond a shallow depth, and cap the expanded size before extraction begins. If a workflow truly depends on archives, unpack them inside a sandbox with no network access and no route to company systems, and pass only the files that clear every earlier check.
Limit what reaches the model as well. Long documents should be split and handled by a defined extraction step that returns structured fields. Pasting a whole document into a prompt makes the agent harder to control, makes its outputs harder to check, and makes it easier for hostile text inside the document to compete with your instructions. Treat the document as a source of fields and passages, not as a set of commands.
Malware scanning and quarantine
Malware scanning should happen before any parser, preview or agent touches a file. Store every incoming file in a quarantine location that the agent cannot read and that never executes its contents. Only files with a passing verdict move to the working location. The scanning step should return a verdict you can log, not a silent pass that nobody can later explain.
A scanner is one layer, not a guarantee. Signature-based tools can miss new threats, and a clean result only says that known threats were not found. This is why the parsing step also runs in isolation, with limited permissions and a time limit, and why any write action the agent proposes still needs a separate approval, whatever the file contained. Defense in depth is slower to explain than a single tool, but it is the design that holds when one layer fails.
Decide in advance what happens when a scan cannot complete. A timeout or a scanner outage should keep the file in quarantine and notify a named person. Treat could not check as a rejection that waits for review, never as a pass. Several rules keep quarantine honest:
- Keep quarantine storage separate from working folders and from any shared drive the agent can search.
- Give the intake service write access to quarantine and no other permission on that location.
- Never let the agent open a file that lacks a passing verdict in the log.
- Apply the company's own retention policy to quarantined files, including deletion of rejected files on schedule.
Rejection, escalation and the audit trail
Rejections should be specific enough for a sender to fix the problem and plain enough to reveal nothing about internal rules. Name the expected format and the size limit. Say what to send instead. Keep the detection method, the threshold values for scanners and the names of reviewers out of the message.
Borderline files need a human decision. Escalate to a named reviewer when a file sits near a limit, contains active content the workflow sometimes needs, or comes from a sender outside the usual list. The reviewer's decision becomes part of the record, so the rule can be adjusted on evidence rather than on memory. An exception that is granted once should be visible in the log every time the same sender tries again.
The audit trail should answer four questions: what arrived, which check decided, why it was decided that way, and who approved any exception. Those records also support incident response. If a supplier mailbox is later found to be compromised, you can find every file it delivered, the verdicts on each, and whether any of them reached the agent's working context. For a broader view of how permissions and records fit together, the acceptance checklist for an AI agent integration gives a useful structure for reviewing the controls before go-live.
How Be Human handles document intake in a managed setup
In a Be Human engagement, document intake is designed as part of the agent's tool layer rather than added later. The engagement defines which document types the role may accept, sets size and archive limits for each workflow, and places quarantine, scanning and parsing outside the agent's working memory. Approval boundaries are written down, so a file that passes intake still cannot trigger a payment, a record change or an outgoing message without the named approver. Managed operations then cover monitoring of rejection patterns, periodic permission review, updates when scanners or parsers change, and incident response when a suspicious file gets through. If you are not yet sure which document flow should be the first one handed to an agent, the free Be Human AI diagnostic is designed to help you find that first task.
Frequently asked questions
Can an agent rely on the file extension to decide what a document is? No. The extension is chosen by the sender and can be wrong or deliberately misleading. Detect the type from the file's content and compare it with the types your workflow allows, then record the result so the decision can be reviewed later.
Is a malware scan enough before accepting customer documents? A scan is necessary but not sufficient. It catches known threats, but it cannot prove a file is safe. Pair it with type checks, size limits, isolated parsing, quarantine and a rule that any write action needs its own approval.
What size limits should we set for document uploads? Start from the largest legitimate document the workflow receives, add a margin, and set separate limits for individual files, upload batches and page counts. Review those values after real traffic shows what normal uploads look like. Limits set too low block valid work, and limits set too high leave the parser exposed.
Should the agent open rejected files to explain the problem to the sender? No. The rejection message should come from the verdict record, which states the expected format and the reason in plain language. Letting the agent open a file that failed intake would bypass the control that was meant to protect it.
Your next step
See where an AI agent fits in your company first.
Take the free Be Human AI diagnostic. A few questions about your work show which task to hand to an agent first, what it needs to know and where a person approves.
Be Human editorial guidance. Examples are illustrative unless explicitly attributed. Sources provide background; implementation choices depend on your workflow.


