What is observe()?
observe allows you to turn any page into a checklist of reliable, executable actions. It discovers key elements, ranks likely next steps, and returns structured actions (selector, method, args) you can run instantly with act or use to precisely target extract so workflows are faster, cheaper, and more resilient.
Why use observe()?
Explore
When you’re unsure what’s on a page or need to discover available actions
Plan
When building complex workflows, plan ahead all the actions you’ll need to take
Cache
When you want to remember actions for the future and avoid LLM calls
Validate
Before performing critical actions to ensure elements exist
Using observe()
Calling observe supercharges other Stagehand methods. Use it to plan workflows, speed up act, and precisely target extract. Using observe helps you explore what’s possible on a page by giving you a list of suggested actions.
Observe with Act
You can validate the action (method, selector, arguments…) and then pass it toact to avoid extra LLM inference.
Performance Tip: Acting on multiple
observe suggestions will minimize the number of LLM calls for multi-step actions and speed up your workflow 2-3x.Plan ahead
You can use multiple suggestions fromobserve to preview a batch of actions. For example, when filling a form you could ask observe to find all the fields and then pass them in to act. Call the LLM once, act multiple times.
Observe and Extract
Usingobserve to focus extract on a specific section of the page (like a table, a form, a list…) minimizes the context needed for an extraction.
Savings Tip: Pass the selector to
extract to reduce LLM token usage by 10x for verbose websites!Best Practices
Choose the right commands
- Do this
- Don't do this
- Use
observewhen a yes/no answer will gate an action (e.g., “Find the Submit button”), then conditionallyact. - Use
extractfor information-only questions (e.g., “What’s the page title?”, “How many results are listed?”).
- Discover and plan with
observe: Useobserve("Find…")to map actionable elements and preview next steps. - Scope
extractwith selectors fromobserve: Firstobserve("Find the data table"), then passselectortoextractto reduce tokens and boost accuracy.
Conserve LLM tokens
Optimize performance by directly passingObserveResult to act (e.g., await page.act(results[0])) to save LLM tokens. Batch operations by using observe once to find elements, then act on each. Cache and reuse stable observe results for familiar pages, using self-healing if layouts change.
Build your own cache
Check out the guide on how to build your own action cache
Improve Accuracy
Be precise with instructions, e.g., “Find the primary CTA in the hero” for better results. For iframes, setiframes: true and wait for networkidle. Use observe selectors in extract to limit context.
Prompting Best Practices
Check out the guide on how to improve the accuracy of your results
Action Validation
Before performing critical actions, validate the suggestion’smethod, selector, and arguments to prevent misclicks. If a direct act fails, use observe with the same prompt to verify the method, then proceed with the suggested action.
Troubleshooting
No elements found
No elements found
Problem:
observe returns empty arraySolutions:- Make sure the element exists on the page
- Use explicit instructions to find the element
- Ensure page has fully loaded
- Look at the debugging logs, if the element is there then the LLM might be hallucinating/not catching it.
Inaccurate element descriptions
Inaccurate element descriptions
Problem: Descriptions don’t match actual elementsSolutions:
- Use more capable models: check evals for the best models for your use case
- Provide more specific instructions
- Log inference to file (see debugging logs) to get an LLM trace
Wrong method identified
Wrong method identified
Problem: The method identified is not validSolutions:
- Check the supported actions
- Provide more specific instructions
- Validate the method, if invalid override with one of the supported ones

