Skip to content

API Reference parrot_tools.scraping.plan_generator

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.plan_generator

View source

PlanGenerator — LLM-based scraping plan generation.

Builds a prompt from a page snapshot, calls the LLM client, and parses the JSON response into a ScrapingPlan.

Attribute PLAN_GENERATION_PROMPT

Attribute PLAN_REFINEMENT_PROMPT

Alias PageSnapshot

Re-exported from parrot_tools.scraping.page_snapshot.PageSnapshot.

Class PlanGenerator

Generates ScrapingPlan from URL + objective using an LLM client.

The LLM client must support async def complete(prompt: str) -> str.

Parameter Type Default Description
llm_client Any Any object with an async complete(prompt) method.

Method PlanGenerator.generate

Generate a scraping plan via LLM inference.

When snapshot is not provided and auto_snapshot is True, the generator fetches the page via a lightweight aiohttp GET and builds a snapshot from the HTML. Fetch failures degrade to an empty snapshot rather than raising.

generate(url: str, objective: str, snapshot: Optional[PageSnapshot] = None, hints: Optional[Dict[str, Any]] = None, auto_snapshot: bool = True, snapshot_fetcher: Optional[Callable[[str], Any]] = None) -> ScrapingPlan

Parameter Type Default Description
url str Target URL to scrape.
objective str Natural language goal for the scraping operation.
snapshot Optional[PageSnapshot] None Pre-built snapshot (skips auto-fetch when provided).
hints Optional[Dict[str, Any]] None Optional dict of hints to bias plan generation.
auto_snapshot bool True If True and no snapshot is supplied, fetch one from url before prompting the LLM.
snapshot_fetcher Optional[Callable[[str], Any]] None Optional async callable (url) -> PageSnapshot used instead of the default aiohttp-based fetcher. Use this to inject a browser-driven fetcher for JS pages.

Returns: ScrapingPlan — A validated ScrapingPlan parsed from the LLM response.

Raises:

  • ValueError — If the LLM response cannot be parsed into a valid plan.

Method PlanGenerator.refine

Regenerate a plan given the failure signals from a prior run.

The prompt shows the LLM its previous plan, what came out of the extractor, what step errors fired, and a FRESH DOM snapshot captured after the prior plan ran — so it reflects any clicks / scrolls / expansions already applied. Expected to return a full replacement plan that corrects the mistakes.

refine(url: str, objective: str, prior_plan: ScrapingPlan, extraction_summary: str, step_errors: str, diagnosis: str, snapshot: Optional[PageSnapshot] = None) -> ScrapingPlan

Parameter Type Default Description
url str Target URL.
objective str Original scraping objective.
prior_plan ScrapingPlan The plan that produced weak results.
extraction_summary str Human-readable summary of what came out (row counts, null-field ratios, example values).
step_errors str Summary of failed steps (one line each) — may be empty string when everything ran but extracted little.
diagnosis str Scoring function's reasons (e.g. "faq: 0 rows; prepaid_plans: 3 rows, 40% empty fields").
snapshot Optional[PageSnapshot] None Post-execution DOM snapshot for the LLM to anchor new selectors on.

Returns: ScrapingPlan — A refined ScrapingPlan (full replacement, not a diff).

Alias ScrapingPlan

Re-exported from parrot_tools.scraping.plan.ScrapingPlan.

Alias fetch_snapshot

Re-exported from parrot_tools.scraping.page_snapshot.fetch_snapshot.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally