Show HN: Robust LLM extractor for websites in TypeScript
TL;DR Highlight
Converts HTML to markdown and extracts schema-based structured data with LLMs in TypeScript.
Who Should Read
Backend TypeScript developers whose LLM scraping pipelines suffer from token costs and malformed JSON.
Core Mechanics
- HTML becomes markdown before the LLM sees it
- The library converts HTML into LLM-ready markdown before extraction.
- Options include main-content-only extraction and tracking-parameter cleanup.
- A Zod schema fixes the output shape
- It uses LLM JSON mode to extract data matching your Zod schema.
- Token usage limits and tracking are included.
- There is a recovery step for broken JSON
- It sanitizes and recovers failed JSON output.
- The README says this helps most with deeply nested objects and arrays.
- URL validation is automatic
- It handles relative URLs and removes invalid ones.
- It also repairs markdown-escaped links.
- Any LangChain chat model plugs in
- Pass OpenAI, Gemini, Anthropic, Ollama or other LangChain models via the llm option.
- With OpenAI models, use .nullable() instead of .optional().
- Works with Playwright and a browser agent
- Load pages with Playwright and pass the HTML to the extractor.
- For clicks and searches, navigate first with @lightfeed/browser-agent.
- An option keeps the meaning of numbers via CSS classes
- annotateNumberClasses appends the element's CSS class next to numbers.
- This preserves whether a number is a price, rating or review count.
Community Reactions
- Commenter worried about content lost in markdown conversion
- A comment asked for data on how often tables or other info get lost.
- They also asked which open-source models work best.
- Opinion that prompt injection hardening is needed
- One comment said the extraction prompt needs hardening against prompt injection.
- Experience that LLM scraping is slow and costly
- A commenter tried LLMs for scraping and found it too slow and still expensive at millions of pages.
- Pushback on the malformed JSON premise
- One commenter said they never hit malformed JSON with structured outputs.
- They also criticized the docs and replies as looking like raw Claude output.
- Criticism of anti-bot features and robots.txt
- Comments pointed out the tool ignores robots.txt.
- The author replied they will drop the stealth browser for plain Playwright and remove anti-bot as a feature.
- Info that Gemini 2.5 flash is being deprecated
- A commenter noted the deprecation by June 17 and suggested updating examples to Gemini 3 Flash.
How to Apply
- Compare tokens of HTML vs markdown on your pages
- Run convertHtmlToMarkdown on a few sample pages today and compare token counts with the raw HTML.
- Check by eye whether tables and lists survive.
- Define the extraction schema in Zod with describe on every field
- Write concrete format and source hints in each description.
- If you use OpenAI, switch optional to .nullable().
- Set extractMainHtml per page type
- Turn it on for list and article pages.
- Leave it off for single product detail pages.
- Add prompt injection defense to the extraction prompt
- State in the prompt that web content is data, not instructions.
- Test whether injected instructions on a page change the output.
Try It
// Terminal: npm install @lightfeed/extractor @langchain/core @langchain/google-genai zod
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import { extract, ContentFormat } from "@lightfeed/extractor";
import { z } from "zod";
const schema = z.object({
title: z.string().describe("Article title"),
sentiment: z.string().describe("One of positive, neutral, negative"),
});
const html = await (await fetch("{{URL}}")).text();
const result = await extract({
llm: new ChatGoogleGenerativeAI({
apiKey: process.env.GOOGLE_API_KEY,
model: "gemini-2.5-flash",
temperature: 0,
}),
content: html,
format: ContentFormat.HTML,
sourceUrl: "{{URL}}",
schema,
htmlExtractionOptions: { extractMainHtml: true },
});
console.log(result.data, result.usage);Terminology
Related Papers
Why Do LLMs Help with Scientific Misconduct Requests and What to Do About It?: Increasing the Trustworthiness of AI for Science
Adding an intention-analysis system prompt raised refusal of misconduct requests from 58% to 87%.
How Specification Explicitness Shapes Failure in LLM-Generated Code
Spelling out invariants, edge cases and constraints cut hidden-test failures in LLM code by 47.2%.
Same Task, Different Statement: When and How Reformulation Helps LLM Problem Solving
Rewriting problem statements to fit their type raises LLM accuracy, but blind rewriting hurts.
Show HN: STE80 Humanizer – de-AI text by writing 80% of the way to ASD-STE100
A skill strips 26 AI tells and rewrites text in short ASD-STE100-style sentences
Character-Name Concentration in LLM Fiction: Measuring Displacement and Mitigating Repetition
Drafting name candidates and filtering by frequency cut LLM character-name repetition by 95%
LLM Voice
Martin Fowler: LLM-drafted prose keeps an uncanny tone even after human editing.
The Instruction Tax on Factual Recall: Base Models Can Beat Their Instruction-Tuned Counterparts
Few-shot completion with repeated sampling on a base model beat chat: F1 0.684 vs 0.568
AI is a tool and using it well takes skill
A rebuttal to Hickey: LLMs are tools, and skill in directing and checking them decides the outcome