Workflow:AI4Finance Foundation FinRobot SEC RAG QA
| Knowledge Sources | |
|---|---|
| Domains | RAG, SEC_Filings, Equity_Research |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
End-to-end process for answering questions about a company's 10-K filing using BM25 retrieval over SEC EDGAR filings, grounding the LLM answer in actual regulatory disclosures with source citations.
Description
This workflow fetches the latest 10-K filing from SEC EDGAR, rebuilds a BM25 index from cached document chunks, retrieves the most relevant passages for a user question, and produces an LLM answer grounded in the retrieved excerpts with section-level citations. Every excerpt is sanitized as untrusted content to prevent filing-embedded instruction injection.
- Goal: A factual answer to a user question, grounded in the company's actual 10-K disclosures, with source-section citations.
- Scope: From a ticker and a question through 10-K fetch, BM25 retrieval, and an LLM answer with citations.
- Strategy: BM25 retrieval grounds the LLM in real filing text; the LLM answers only from the provided excerpts.
Usage
Execute this workflow when you need to ask a specific question about a company's 10-K filing — risk factors, business description, MD&A, segment data — and get an answer grounded in the actual regulatory disclosure with citations.
- Input State: A valid public ticker symbol and a natural-language question.
- Desired Output: A factual answer citing specific 10-K sections (e.g., [Item 1A - Risk Factors]), or an explicit statement that the excerpts are insufficient.
Execution Steps
Step 1: 10-K Fetch and Chunk Extraction
Fetch the latest 10-K filing from SEC EDGAR and extract serializable text chunks. The data layer pulls the 10-K via the SEC provider, which parses the filing into labeled sections (Item 1, Item 1A, Item 7, etc.) and stores them as plain-dict `rag_chunks` in the cache. The chunks carry a `source` label and a `chunk_index` for citation.
Key considerations:
- The provider stores plain dicts, not a live BM25Index, so the cache can round-trip through JSON without serialization errors.
- The 10-K fetch is cached; a repeated question on the same ticker rebuilds the index cheaply from the cached chunks.
- If no 10-K is available, the workflow raises a clear error rather than producing an ungrounded answer.
Step 2: BM25 Index Rebuild and Retrieval
Rebuild the BM25 index from the cached chunks and retrieve the top-k passages for the question. The `BM25Index` is constructed from the `Chunk` objects, and `search` returns the top-k chunks ranked by BM25 relevance score. Each result carries a relevance score for the prompt context.
Key considerations:
- The index is rebuilt on each call (cheap) from the cached chunks — it is a runtime artifact, not a stored one.
- The `top_k` parameter (default 5) controls how many passages are retrieved.
- If no relevant passages are found, the workflow returns a "no results" message rather than forcing an ungrounded answer.
Step 3: Context Assembly and Sanitization
Assemble the retrieved excerpts into a grounded prompt context, sanitizing each excerpt as untrusted content. Each chunk's source label is sanitized (tag/heading escape vectors removed), and the chunk text is wrapped in an explicit `<untrusted_filing_excerpt>` block. The prompt instructs the LLM to treat the excerpts strictly as data to quote and analyze, never as instructions.
Key considerations:
- Filing text is third-party content; EDGAR HTML parsing can pick up arbitrary embedded text, so every excerpt is sanitized.
- The untrusted-block wrapper and the prompt instruction prevent filing-embedded instruction injection (the same defense applied to news headlines).
- The context is assembled with section labels and relevance scores so the LLM can cite specific sources.
Step 4: LLM Answer Generation
The LLM answers the question using only the provided excerpts, citing specific sections. The system prompt instructs the agent to base its answer solely on the document excerpts, cite the source section for each key claim, and explicitly state when the excerpts are insufficient. The agent returns a factual, cited answer.
Key considerations:
- The LLM is constrained to the provided excerpts — it does not draw on parametric memory.
- The system prompt enforces citation discipline (e.g., [Item 1A - Risk Factors]).
- If the excerpts are insufficient, the LLM says so explicitly rather than fabricating.