How EduGenius Keeps AI-Generated Content Strictly Faithful to an Uploaded Source
When you upload a PDF, image, or text file to EduGenius, the server doesn't hand the whole document to the AI model as-is. It first matches source text against the words in your prompt and drops passages that don't relate, then checks your prompt for phrasing like "only from my notes" or "strictly from this document."
If it finds that phrasing, it switches into a code-enforced strict mode: the model is instructed to use only the uploaded material and add no outside facts, and the system keeps a substantially larger slice of your source text than it does by default.
Quick Answer: EduGenius runs uploaded source text through intent-first filtering before it ever reaches the AI model, keyword-matching source chunks against your typed prompt and discarding chunks with no overlap. Separately, the server scans your prompt for strict-fidelity phrasing ("only from my notes," "strictly from this document," "do not use outside knowledge," and similar patterns). When detected, it raises the retained source budget from 6 chunks capped at 3,500 characters per source to 24 chunks capped at 12,000 characters, and prepends an explicit instruction telling the model to use only the provided material.
That's a specific, checkable mechanic, not a marketing claim. It lives in app/api/generate-content/route.js, in a function called applyIntentFirstFiltering, alongside a detectSourceFidelityMode check that runs a short list of regular expressions against your prompt text before any source content gets filtered or forwarded.
Most of what gets written about AI and source material stays at the surface: "upload a document and generate a quiz from it." The more useful question is what happens to your document between the upload and the output, because that's the part that decides whether the result actually reflects what you gave it.
The Real Problem: An Uploaded Source Doesn't Guarantee a Faithful Output
Handing a document to an AI model doesn't automatically mean the model's output sticks to that document. A general-purpose language model has a large amount of background knowledge baked into it, and nothing about receiving extra text in a prompt forces it to ignore that background knowledge in favor of what you just gave it.
Why This Matters More in a Classroom Than It Sounds
A teacher uploading a source usually has a specific reason: a worksheet needs to test recall of this reading, not general knowledge about the topic. When output quietly drifts outside the source, the mismatch is easy to miss and hard to catch after the fact.
- A quiz question tests a fact that's true but doesn't appear anywhere in the uploaded reading.
- A study guide summarizes the general topic instead of the specific version of it a teacher's notes actually cover.
- A vocabulary list pulls terms that sound plausible for the subject but were never in the source document at all.
What Grounding Research Actually Says
This isn't a novel concern specific to classrooms. It's the same problem researchers have described for years under the term grounding, and it has a specific technical answer.
Patrick Lewis and colleagues at Facebook AI Research introduced the term retrieval-augmented generation (RAG) in a 2020 paper presented at NeurIPS, describing a model that retrieves relevant passages from a document store and conditions its output on them, rather than relying purely on training knowledge. The core idea, that output quality improves when a model draws from retrieved, relevant text instead of its general training, is the same idea behind intent-first filtering.
A 2023 survey in ACM Computing Surveys by Ziwei Ji and co-authors catalogs the resulting failure mode under the term hallucination: fluent, plausible-sounding text that isn't actually supported by the input given to the model.
UNESCO's 2023 guidance on generative AI in education raises a related, classroom-specific concern: AI tools used for teaching need mechanisms that keep generated content traceable to verified source material, not just plausible on its face.
None of that research is about EduGenius specifically. It's the backdrop that explains why "upload a source" and "the output only reflects that source" are two different claims, and why closing the gap takes deliberate engineering rather than a hopeful prompt.
What Actually Happens When You Upload a File
Before any filtering or fidelity logic runs, a source has to get through file validation and text extraction, and that pipeline is real rather than a thin wrapper. Three input types are supported, and each is capped differently.
Supported File Types and Limits
| Source type | Max size | Extraction method | Notes |
|---|---|---|---|
| 10 MB | Gemini Vision (OCR-capable), with a local pdf-parse fallback | Capped at 30 pages in the current phase | |
| Image (JPEG, PNG, WebP) | 5 MB | Gemini Vision OCR | Handles scanned or photographed text |
| TXT / CSV | 2 MB | Parsed locally, no AI call | Text is decoded and sanitized directly |
Up to three sources can be attached to a single generation request. Every uploaded file is checked against its magic bytes, the actual binary signature at the start of the file, not just the filename extension or the browser-reported MIME type. A file renamed from .exe to .pdf doesn't pass as a PDF; the server checks for the real %PDF signature before doing anything else with it.
Two Different Extraction Paths, Not One
It's worth being precise, since it's easy to assume "AI-powered" applies uniformly across every file type — it doesn't.
- PDFs and images go through Gemini Vision, EduGenius's AI extraction layer, which performs OCR and returns extracted text. If a scanned page or an embedded diagram contains text, Gemini reads it the same way it reads a typed page.
- PDF extraction has a local fallback. If the Gemini provider times out or is temporarily unavailable, the system falls back to
pdf-parse, a local, non-AI PDF text parser, so a temporary AI-provider hiccup doesn't necessarily fail your upload outright. - TXT and CSV files skip AI extraction entirely. They're decoded and sanitized locally, on the server, with no model call involved. There's no OCR step needed because the text is already machine-readable.
That distinction matters for cost and reliability: typed notes saved as .txt extract deterministically, with nothing sent to an external AI model. A photographed whiteboard or scanned worksheet genuinely needs OCR, which is why images and PDFs route through Gemini Vision instead.
Extracted Text Gets Sanitized Before It Reaches the Model
Once text is extracted, the pipeline strips a defined list of prompt-injection markers, patterns like [INST], <<SYS>>, ### system:, and phrases resembling "ignore previous instructions," before that text is used anywhere downstream. This exists for a narrow, honest reason: an uploaded PDF or image is content from outside the application, and a malicious or corrupted file could theoretically embed text designed to hijack the generation prompt.
Stripping known injection patterns and capping how much raw text gets carried forward closes that specific door. It's a sensible input-hygiene step, not a claim that every possible adversarial document is neutralized.
The Real Differentiator: Intent-First Filtering
This is the part of the pipeline that actually decides how faithful your output is to what you uploaded, and it runs on every generation request that includes a source. The server doesn't dump your whole PDF into the prompt next to your instructions. It filters first.
How the Filtering Actually Works
When a request includes both typed instructions and one or more sources, the server splits your uploaded text into paragraph-sized chunks and compares each one against the meaningful words in your typed prompt.
- Your typed prompt is tokenized into keywords, with common stop words (like "the," "and," "quiz," "generate") filtered out so the comparison focuses on substantive terms.
- Each chunk of your uploaded source is tokenized the same way.
- A chunk is kept if it shares at least one meaningful keyword with your prompt; a chunk with zero overlap is dropped.
- The surviving chunks are reassembled, capped at a maximum count and character budget, and placed back into the prompt under a clearly labeled heading: "RELEVANT SOURCE EXCERPTS (PRE-FILTERED FOR INTENT ALIGNMENT)."
In practice, a 12-page PDF uploaded alongside "make 10 questions about photosynthesis" doesn't get handed to the model whole. The system prioritizes chunks that actually mention photosynthesis-adjacent terms, rather than treating every paragraph as equally relevant.
The Trigger: How You Phrase the Request Changes the Behavior
Here's the mechanic that makes this genuinely different from "upload a file and hope for the best." Before filtering runs, the server checks your typed prompt against a small set of patterns designed to catch strict-fidelity language, phrasing like:
- "only from my notes"
- "strictly from this document"
- "based only on the source"
- "from my class notes only"
- "do not use outside knowledge"
If any of these (or close variants) match, the request flips into what the code labels source fidelity mode: strict. Two things change at once when that happens:
- The model gets an explicit instruction added to the prompt: "SOURCE FIDELITY MODE: STRICT. Use ONLY the learner-provided source material. Do NOT add outside facts."
- The retained-text budget widens substantially. In default mode, the system keeps up to 6 matched chunks per source, capped at 3,500 characters. In strict mode, that rises to 24 matched chunks per source, capped at 12,000 characters, roughly three-and-a-half to four times more source text retained.
That second change matters as much as the instruction itself. A strict-fidelity instruction paired with a thin slice of the source would still leave the model filling gaps with outside knowledge, simply for lack of enough source text to draw from. Widening the budget is what makes the instruction realistic to follow, not a suggestion layered on top of an unchanged process.
What Happens to Passages That Don't Match Anything
Default and strict mode also diverge on what happens when a source has no matching chunks against your prompt's keywords.
- In default mode, a source with zero keyword overlap against your prompt gets dropped entirely rather than forwarded to the model.
- In strict mode, a source with no matching chunks isn't dropped. Instead, the system falls back to keeping the first slice of that source (up to the strict character cap) rather than discarding it, on the reasoning that a source you explicitly said to use exclusively shouldn't be silently excluded just because none of its language echoes your literal keywords.
Comparing the Two Modes Directly
| Behavior | Default mode | Strict fidelity mode |
|---|---|---|
| Trigger | No strict-fidelity phrasing detected | Phrasing like "only from my notes" or "strictly from this document" detected |
| Max chunks retained per source | 6 | 24 |
| Max characters retained per source | 3,500 | 12,000 |
| Source with zero keyword matches | Dropped from the prompt entirely | Retained, truncated to the cap, rather than dropped |
| Explicit model instruction added | No | Yes — "use ONLY the learner-provided source material" |
The practical upshot: type "make a 10-question quiz on the water cycle," and the system quietly keeps the source parts that relate to the water cycle, a reasonable relevance filter. Type "using only my notes on the water cycle" instead, and it both retains far more of the document and tells the model, explicitly, not to reach outside it.
What This Costs: Ingestion Credits Are Separate From Generation Credits
Processing an uploaded source spends its own credits, charged separately from the credits spent generating the worksheet, quiz, or activity itself. That split exists because extraction, especially OCR on a scanned PDF, is a real, metered cost distinct from the generation step that follows it.
How Ingestion Cost Scales
- Images cost a flat rate per file, reflecting that OCR on a single image is a bounded amount of work regardless of exactly how much text it contains.
- PDFs and text files scale with how much text actually gets extracted. A short document costs a minimum baseline; longer documents cost more, in proportion to extracted character count, up to a capped maximum so a single very long source can't run away in cost.
In practical terms, images generally cost less than PDFs: a flat per-image rate tends to land below the scaled cost of a PDF with a meaningful amount of extracted text, though a very short PDF can land near the same minimum as an image.
Access Is Plan-Gated, With a Daily Cap Regardless of Tier
Source upload isn't available on every plan, and it isn't unlimited on any plan.
- Free-plan accounts cannot use source upload at all. A Starter plan or higher is required before the file, image, or text-upload controls become usable.
- A daily cap of 5 source-upload attempts applies regardless of plan tier, on top of separate monthly caps that vary by plan. Even on a higher tier, source upload is metered, not unlimited.
Where Storage and Privacy Fit In
Uploaded files are stored with content-hash deduplication: the server checks whether that exact file content, identified by a SHA-256 hash of the bytes, has already been uploaded, and reuses the existing copy rather than duplicating it. Access happens through a time-limited signed URL rather than a permanently public link, so a download link doesn't stay valid indefinitely. Worth knowing plainly, not a claim of a full security audit: it's sensible storage hygiene, sized to what a file-upload feature needs.
A Walkthrough: Two Prompts, Two Outcomes
The clearest way to see the difference is to compare the same uploaded source under two different prompts, since the file itself never changes, only the phrasing does.
Scenario 1: A Standard Prompt
Picture a middle school science teacher uploading a scanned PDF of a two-page reading on the water cycle, then typing: "Make a 10-question multiple-choice quiz about the water cycle for my 7th graders."
No strict-fidelity phrasing appears in that prompt, so default mode applies. The server extracts the PDF text through Gemini Vision, splits it into chunks, keeps up to 6 chunks per source (up to 3,500 characters) that share keywords with "water cycle" and "quiz," and generates from that filtered slice. If the uploaded PDF happened to include an unrelated appendix, a glossary of general earth-science vocabulary, for instance, chunks from that appendix without water-cycle-related keywords are more likely to be filtered out rather than folded into the quiz.
Scenario 2: The Same Source, a Strict-Fidelity Prompt
Now picture the same teacher, same uploaded PDF, but typing instead: "Make a 10-question quiz using only my notes on the water cycle. Do not use outside information."
That phrasing trips detectSourceFidelityMode. The retained-text budget jumps to 24 chunks per source, up to 12,000 characters, and the prompt sent to the model is prepended with an explicit instruction to use only the provided material and add no outside facts. If a passage in the PDF doesn't share obvious keywords with "water cycle," it's still more likely to survive in this mode, rather than being silently dropped the way it would be in the default pass.
Why the Distinction Is Worth Knowing, Not Just Trivia
A teacher who wants a quiz confined to one specific reading, for a closed-book check or a comprehension assessment, gets meaningfully different behavior by adding a few words of phrasing. That's not a hidden setting buried in an options panel; it's detectable directly from how the request is written, worth being intentional about rather than leaving to chance.
Pro Tips
- Say it plainly if fidelity matters. Phrasing like "only from my notes" or "strictly from this document" is what triggers strict mode; a vague reference to the source without that language stays in default mode.
- Keep the source focused on what you're testing. Even in strict mode, filtering still runs; a source padded with unrelated material still gets triaged by keyword relevance first.
- Use TXT for typed notes when you have them. Skipping OCR entirely means faster, more literal extraction with no AI-provider dependency for that step.
- Check the 30-page PDF cap before uploading a long reading. A source that runs past the cap won't be read in full; splitting it or pasting the relevant excerpt as text may serve better.
What to Avoid
- Don't assume "I uploaded a PDF" alone guarantees strict grounding. Without strict-fidelity phrasing in your prompt, the system applies ordinary relevance filtering, not a hard ban on outside facts.
- Don't upload a source expecting free-plan access. Source upload requires a Starter plan or above; it isn't available on the free tier at all.
- Don't treat the daily cap as a soft limit. Five source-upload attempts per day applies across all plan tiers, separate from monthly caps.
- Don't skip review of the generated output, strict mode or not. Filtering and instructions reduce drift toward outside facts; they don't replace a teacher's own check of the final questions.
Key Takeaways
- Uploaded source text is filtered before it reaches the model, keyword-matched against your typed prompt so irrelevant chunks are dropped rather than forwarded wholesale.
- A detectable phrase, not a toggle, controls strict fidelity. Language like "only from my notes" or "strictly from this document" triggers a code-enforced mode that instructs the model to use only the source and widens the retained-text budget from 6 chunks/3,500 characters to 24 chunks/12,000 characters per source.
- Extraction method depends on file type. PDFs and images go through Gemini Vision OCR (with a local
pdf-parsefallback for PDFs); TXT and CSV files are parsed locally with no AI call at all. - Extracted text is sanitized against known prompt-injection markers before it's used downstream, a proportionate defense against a malicious or corrupted uploaded file.
- Ingestion credits are separate from generation credits, scaled by extracted text volume, with images generally costing less than PDFs; source upload requires a Starter plan or above and is capped at 5 attempts a day regardless of tier.
- Files are deduplicated by content hash and served through time-limited signed URLs, sensible storage hygiene rather than a full security guarantee.
- The underlying idea, grounding output in retrieved source text, has real research behind it, from the 2020 retrieval-augmented generation work at Facebook AI Research to hallucination research and UNESCO's guidance on generative AI in education.
Frequently Asked Questions
Does uploading a PDF automatically mean the AI only uses that PDF?
Not automatically. By default, EduGenius filters your source for relevance and keeps the matching portions, but it doesn't forbid outside knowledge unless your prompt includes strict-fidelity phrasing like "only from my notes" or "strictly from this document."
What phrasing actually triggers strict fidelity mode?
Patterns including "only from my/the/this notes/source/document," "strictly from my/the/this document," "based only on my/the/this source," "from my class notes only," and "do not use outside knowledge" (and close variants of each).
What changes when strict mode is on?
The model gets an explicit instruction to use only the uploaded material and add no outside facts, and the system retains far more source text per source: up to 24 chunks and 12,000 characters, versus 6 chunks and 3,500 characters by default.
Does every file type go through AI extraction?
No. PDFs and images are extracted through Gemini Vision OCR (PDFs fall back to a local parser if Gemini is temporarily unavailable). TXT and CSV files are parsed locally with no AI model call involved in extraction at all.
How many sources can I upload for one generation request?
Up to three sources per request, combining PDF (10MB), image (5MB, JPEG/PNG/WebP), and TXT/CSV (2MB) files, with PDFs capped at 30 pages in the current phase.
Does source upload cost extra credits?
Yes. Source ingestion is charged separately from generation credits, scaled by how much text is extracted; images generally cost less than PDFs since PDF cost scales with extracted character count up to a capped maximum.
Can free-plan users upload a source?
No. Source upload requires a Starter plan or above. A daily cap of 5 upload attempts also applies across every plan tier that has access.
Is there any protection against a malicious uploaded file?
Extracted text is sanitized against known prompt-injection markers before it reaches the model, and every file is validated against its actual binary signature (magic bytes), not just its filename or declared type. This is a proportionate input-hygiene measure, not a claim of comprehensive security testing.