
AgentQL vs Diffbot for LLM agent grounding — can I avoid sending raw HTML to the model?
Quick Answer: Yes—you can avoid sending raw HTML to your LLM agent. Both AgentQL and Diffbot turn web pages into structured data, but they do it in different ways. AgentQL lets you define the exact JSON schema you want via a query language and extracts it on demand, while Diffbot exposes pre-defined entity types (Articles, Products, etc.) via its Knowledge Graph and APIs.
Why This Matters
If you’re grounding LLM agents on the open web, raw HTML is the bottleneck. It bloats context windows, increases hallucinations, and forces you to maintain fragile XPath/CSS selectors or brittle parsing code. A schema-first layer—where you ask for specific fields and get predictable JSON back—turns the web into something much closer to an API surface your agents can reliably consume.
Key Benefits:
- Smaller, cleaner prompts: Replace reams of HTML with compact JSON tailored to your task, so you stay within context limits and reduce noise.
- More reliable grounding: Ground agents on structured fields instead of ambiguous HTML text, reducing hallucinations and making reasoning steps easier to verify.
- Less brittle maintenance: Move away from hand-coded selectors and scraping scripts; use AI-powered extraction that self-heals across layout or UI changes.
Core Concepts & Key Points
| Concept | Definition | Why it's important |
|---|---|---|
| Schema‑first grounding | Defining the shape of the data you want (fields, arrays, nesting) before you query the page. | You send only the data your LLM needs, not the entire DOM, which cuts token usage and constrains the agent’s reasoning surface. |
| AgentQL query → JSON | AgentQL analyzes the page structure with AI, finds the elements you requested, and returns consistent JSON matching your query. | Lets you ditch fragile XPath/DOM selectors, reuse the same query across similar pages, and plug JSON output directly into your agent pipeline. |
| Diffbot Knowledge Graph & APIs | Diffbot crawls the web, classifies pages into entities (Article, Product, Organization, etc.), and exposes them via APIs and a pre-built Knowledge Graph. | Great when your use case aligns with Diffbot’s entity types and you want ready-made structured data, not custom page-by-page extraction. |
How It Works (Step-by-Step)
At a high level, both tools help you avoid sending raw HTML to your model, but the workflow and control surface differ.
1. AgentQL: Query the page you care about
With AgentQL, you:
-
Define the shape of your data with a query.
You describe exactly what you want from a given URL—names, prices, dates, table cells, etc.—as a schema:{ products[] { product_name product_price(include currency symbol) rating in_stock } } -
Run it via SDK or REST API.
You call AgentQL through:- Playwright-based Python/JavaScript SDKs, or
- A browserless REST API:
URL → JSON(no browser infra required)
-
Get structured JSON for grounding.
{ "products": [ { "product_name": "Mechanical Keyboard X200", "product_price": "$129.99", "rating": 4.7, "in_stock": true }, { "product_name": "Ergonomic Mouse Pro", "product_price": "$59.00", "rating": 4.4, "in_stock": false } ] }
This JSON is what you feed into your LLM—either as context for a tool call, a system prompt attachment, or part of a retrieval step. No raw HTML, no selectors in your agent code.
2. Diffbot: Use pre-defined extraction & the Knowledge Graph
With Diffbot, the flow is more “API-first” around their entity types:
- Hit a Diffbot extraction endpoint (e.g.,
Article API,Product API), or query the Knowledge Graph if the page/entity is already crawled. - Receive structured data that follows Diffbot’s schema for that entity (title, text, price, brand, etc.).
- Feed that JSON to your LLM for grounding and reasoning.
You don’t write queries describing your target output shape; instead, you rely on Diffbot’s schema and the fields they expose for that entity type.
3. Where AgentQL fits in an LLM agent stack
For LLM agents, AgentQL is often used as:
- A tool or function the model calls:
get_page_data(url, query)→ JSON. - A grounding layer that runs before or alongside your RAG/search system.
- A replacement for Playwright + selectors: you still use Playwright under the hood via AgentQL’s SDKs, but let AgentQL handle locating elements.
A typical tool definition might look like:
{
"name": "get_product_page_data",
"description": "Extracts structured product info from an e-commerce page using AgentQL",
"parameters": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "The product listing URL"
}
},
"required": ["url"]
}
}
Your tool implementation then calls AgentQL with a fixed query and returns the JSON to the model.
AgentQL vs Diffbot for LLM Agent Grounding
Control surface: schema-first vs entity-first
-
AgentQL: You describe exactly what you want per use case:
- Arbitrary fields and nesting
- Complex document structures (e.g., PDF tables, multi-section layouts)
- Different queries for different tasks, even on the same page
-
Diffbot: You rely on Diffbot’s entity schemas:
- Article, Product, Organization, Person, etc.
- Great if your use case fits these shapes
- Less flexible when you need custom, fine-grained extraction from arbitrary layouts
For agent grounding, AgentQL’s schema-first approach is especially useful when the LLM’s tool contract is tightly defined (e.g., [{ name, url, price, discount_percentage }]). You can mirror that contract in your AgentQL query so the JSON output matches your tool schema one-to-one.
Web coverage & freshness
-
AgentQL:
- You control when and what you scrape.
- Works on any accessible web page (and PDFs), including auth-gated flows you script with Playwright.
- Ideal when your agents must interact with live state—forms, dashboards, changing search results.
-
Diffbot:
- Strong coverage for the public web via its crawler.
- Great when you’re okay with Knowledge Graph freshness or batch extraction.
- Less suited to “drive a specific session and read the UI as it appears right now” agent flows.
HTML exposure to the LLM
In both setups, you can keep raw HTML away from the model. The differences are:
-
AgentQL:
- HTML is handled by AgentQL’s engine.
- The LLM sees only the JSON you designed.
- You can strip or aggregate fields before passing data to the model, further shrinking the context.
-
Diffbot:
- HTML is handled by Diffbot’s crawlers and extraction models.
- Again, only JSON hits the LLM.
- If you need fields outside Diffbot’s schema, you may revert to HTML + your own parser or another extraction tool.
Robustness to layout changes
-
AgentQL:
- Uses AI to analyze page structure instead of brittle XPath/CSS selectors.
- Queries are designed to be self-healing across layout changes and dynamic content.
- You refine queries via the AgentQL IDE browser extension and Playground, then reuse them across similar pages.
-
Diffbot:
- Robustness is baked into their generic extractor models.
- You’re insulated from individual site layout changes, but also constrained to what the extractor and schema expose.
For LLM agents that operate on multiple vendors’ dashboards or on long-tail sites where you don’t control the HTML, self-healing schema-first queries can be easier to iterate on than a fixed global schema.
Integration into your stack
AgentQL:
-
Surfaces:
- Python/JS SDKs (Playwright-based)
- REST API (
URL → JSON, browserless) - IDE browser extension for live query creation
- Playground for trial and debugging
-
Ops signals:
- Rate limits by API calls/minute
- Concurrent remote browser sessions
- Remote browser hours for Playwright-style flows
- On-premise deployment available
- 24/7 premium support and a dedicated account manager at higher tiers
Diffbot:
- Surfaces:
- REST APIs for extraction endpoints and Knowledge Graph
- SDKs in major languages
- Typically used as a data backend (batch enrichment, analytics) as much as for live agent flows.
For LLM agents, AgentQL usually plugs in closer to the “tool layer”: it behaves like a dynamic, per-request extractor that mirrors your tool schema. Diffbot often sits more like a data source or “external knowledge API” you query for facts about entities.
Common Mistakes to Avoid
-
Mistake 1: Still sending raw HTML “just in case.”
How to avoid it: Design your agent tools around JSON schemas. For each tool, define the minimal fields the LLM needs (e.g.,[{ title, url, price, rating }]), then:- Implement that schema with an AgentQL query (or Diffbot fields).
- Assert on the shape at the code level before handing it to the model.
-
Mistake 2: Treating the extractor as a black box.
How to avoid it:- With AgentQL, inspect the exact JSON output in the Playground or via tests.
- Use the browser extension to visually confirm what each field maps to on the page.
- Add basic invariants (e.g.,
pricemust match/^\$?\d+(\.\d{2})?$/, arrays not empty) before you trust the data for grounding.
Real-World Example
Imagine you’re building an LLM agent that compares SaaS pricing pages across competitors. The agent needs:
plan_namemonthly_pricebilled_frequencykey_features[]
With AgentQL
You write one query that matches your tool schema:
{
plans[] {
plan_name
monthly_price(include currency symbol)
billed_frequency
key_features[]
}
}
Call this via the Python SDK against any pricing page:
from agentql import AgentQLClient
client = AgentQLClient(api_key="YOUR_API_KEY")
query = """
{
plans[] {
plan_name
monthly_price(include currency symbol)
billed_frequency
key_features[]
}
}
"""
result = client.query_url("https://competitor.com/pricing", query)
You get JSON ready for the agent:
{
"plans": [
{
"plan_name": "Starter",
"monthly_price": "$29",
"billed_frequency": "billed monthly",
"key_features": [
"Up to 3 projects",
"Email support",
"Basic analytics"
]
},
{
"plan_name": "Pro",
"monthly_price": "$79",
"billed_frequency": "billed monthly",
"key_features": [
"Unlimited projects",
"Priority support",
"Advanced analytics"
]
}
]
}
Your LLM tool now consumes a consistent JSON schema across multiple vendors without ever seeing HTML. If a competitor redesigns their pricing layout, AgentQL’s AI-powered selector logic still aims to return the same field structure, so your agent’s reasoning code doesn’t change.
Pro Tip: Keep your AgentQL queries and your LLM tool schemas in a shared module. When you adjust a field (e.g., add
trial_available), update both in one place, then validate with the Playground before deploying—this keeps your agent’s grounding layer behaving like a stable API contract.
Summary
You don’t need to send raw HTML to your LLM agents. Both AgentQL and Diffbot give you structured JSON instead, but they serve different grounding strategies:
- Use Diffbot when your needs align with its predefined entity schemas and Knowledge Graph.
- Use AgentQL when you want schema-first, page-specific extraction that mirrors your tool contracts, works across arbitrary sites (including PDFs), and replaces fragile XPath/DOM selectors with self-healing AI-powered queries.
For LLM agent grounding that feels like calling a custom API on any web page—query → JSON → model—AgentQL is built to make the web AI-ready without flooding your context window with HTML.