Skip to content

Fix: Robust SEC Filing Retrieval via Local Caching & Deep Scanning#147

Open
LutherAbel wants to merge 3 commits intovirattt:mainfrom
LutherAbel:main
Open

Fix: Robust SEC Filing Retrieval via Local Caching & Deep Scanning#147
LutherAbel wants to merge 3 commits intovirattt:mainfrom
LutherAbel:main

Conversation

@LutherAbel
Copy link

@LutherAbel LutherAbel commented Feb 13, 2026

Description:
This PR addresses the "402 Payment Required" error that occurs when users do not have a paid subscription to the Financial Datasets API.

The Goal:
To allow the agent to seamlessly retrieve SEC filings (8-K, 6-K) directly from EDGAR when the paid API is unavailable, instead of failing or falling back to a generic web search.

Key Changes:

  1. Hard Fallback Mechanism:
  • Updated financial-search.ts to intercept 402 errors.
  • If the paid API fails, the system now automatically executes a direct scraper (get_direct_sec_filings) to fetch the data from SEC.gov.
  1. Direct SEC Scraper (sec_scraper.ts):
  • Implemented a robust scraper that parses SEC filing pages to extract Press Releases (Exhibit 99.1).
  • Includes logic to handle various HTML structures (e.g., NBIS, MCHP).
  1. Local Ticker Cache:
  • Added company_tickers.json as a static asset.
  • The scraper prioritizes reading CIKs from this local file to ensure reliable lookups without needing to query the SEC API on every run.

Verification:
Verified that queries like "search NBIS 6-k" and "search SOFI 8-k" now return correct data even without a paid API key.

This PR overhauls the SEC scraping logic to eliminate 402/403 errors and handle non-standard filing formats.

Key Changes:

1. Offline Ticker Cache: Added `company_tickers.json` as a static asset. The scraper now prioritizes reading CIKs from disk to prevent API rate-limiting and IP bans.

2. Deep Scanning Logic: Increased filing scan depth from 5 to 80 in `sec_scraper.ts`. This ensures filings for active companies (e.g., SOFI, ENTG) aren't pushed out of view by high volumes of Form 4s.

3. Hard Fallback Interceptor: Updated `financial-search.ts` to intercept "402 Payment Required" errors. Failed API calls now automatically force-route to the direct SEC scraper.

4. Brute Force Payload Discovery: Improved logic to find exhibit links (e.g., 99.1 Press Releases) even in non-standard HTML structures.

5. System Prompt Restoration: Restored the full financial routing prompt while maintaining the new SEC intercept rules.
@LutherAbel
Copy link
Author

Note on CI Failure: I noticed the CI build failed due to a frozen-lockfile error. This is because I modified package.json to fix the execution script (switching to tsx), but I am working in a Node.js/NPM environment and cannot regenerate the bun.lockb binary lockfile.

Please run bun install to update the lockfile on your end. The logic changes themselves are verified and working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant