Dynamic Web Element Tool Protocol and Fallback Execution Spec
Standardize dynamic DOM element location, self-healing selectors, and runtime tool invocation for web scrapers.
Use this template to specify robust selector resolution, visual fallbacks, and recovery protocols for autonomous agents facing shifting web DOMs. It provides actionable contracts to prevent workflow breaks from frontend refactors.
Role: Lead Reliability Engineer specializing in resilient web automation, DOM mutation recovery, and autonomous scraper tooling.
Context
- Target DOM layout patterns: {{target_dom_patterns}}
- Agent runtime reasoning model: {{llm_runtime_model}}
- Timeout and latency constraints: {{timeout_latency_limits}}
- Mutation detection heuristics: {{dom_mutation_heuristics}}
- Scraping and interaction rate limits: {{rate_limit_policy}}
Task
Create a dynamic element resolution and self-healing tool-calling specification that enables {{llm_runtime_model}} to reliably target and interact with shifting components in {{target_dom_patterns}}.
Method
- Classify target UI elements across {{target_dom_patterns}} into structural, semantic, and accessibility locator hierarchies.
- Specify primary CSS/XPath selector synthesis strategies alongside secondary accessibility-tree heuristics.
- Define multi-layered fallback tiers when primary locators fail against {{dom_mutation_heuristics}}.
- Create a standardized JSON payload structure for passing element bounding boxes, visibility states, and computed attributes to {{llm_runtime_model}}.
- Establish strict execution time budgets adhering to {{timeout_latency_limits}} across all locator attempts.
- Define rate-limiting throttle hooks to ensure tool call frequency complies with {{rate_limit_policy}}.
- Formalize a self-healing patch protocol where newly resolved locators update the persistent selector cache.
Constraints
- MUST NOT rely solely on brittle static class names or auto-generated hashes (e.g., CSS modules).
- Element resolution cascades MUST abort and trigger fallback before exceeding {{timeout_latency_limits}}.
- Tool payloads MUST sanitize raw DOM fragments to minimize context window token consumption.
- The protocol MUST strictly throttle concurrent element lookups in compliance with {{rate_limit_policy}}.
Output format
-
- Locator Cascade Architecture (ordered hierarchy from CSS to Accessibility to Vision)
-
- Tool Interface Specification (JSON Schema for
resolve_element,interact_element, andreport_dom_mutation)
- Tool Interface Specification (JSON Schema for
-
- DOM Sanitization & Token Optimization Guidelines (filtering algorithms and size limits)
-
- Self-Healing Selector Update Protocol (state transition logic for caching verified selectors)
Self-review
- Does the locator cascade enforce strict timeout cutoffs matching {{timeout_latency_limits}}?
- Are DOM payload structures optimized to prevent LLM context bloating?
- Does the self-healing protocol clearly define when a selector cache entry must be invalidated?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.