Act method
Useact() for single actions on web pages. Each action should be focused and clear.
- TypeScript
- Python
- Go
Use element types, not colors
Describe elements by their type and function rather than visual attributes like color.- TypeScript
- Python
- Go
Use descriptive language
- TypeScript
- Python
- Go
Choose the right action verbs
- Click for buttons, links, checkboxes
- Type for text inputs
- Select for dropdowns
- Check/uncheck for checkboxes
- Upload for file inputs
- TypeScript
- Python
- Go
Protect sensitive data
Variables keep sensitive information out of prompts and logs. Stagehand shows the model only the variable name and its optional description, then substitutes the real value into the resolved action right before it runs, so the secret never reaches the model and never appears in the logged action.- TypeScript
- Python
- Go
Extract method
Useextract() to pull structured data from pages. Define clear schemas and provide context.
Schema best practices
Use descriptive field names, correct types, and detailed descriptions. Field descriptions provide context that helps the model understand exactly what to extract.- TypeScript
- Python
- Go
Use proper URL types
Type link fields as URLs so Stagehand resolves them to real addresses instead of the internal element IDs the model chooses.- TypeScript
- Python
- Go
Observe method
Useobserve() to discover actionable elements before acting on them.
Check elements first
Verify elements exist before taking action to avoid errors.- TypeScript
- Python
- Go
Be specific about element types
- TypeScript
- Python
- Go
Sequencing multi-step work
Stagehand v4 has no autonomous agent, so multi-step flows are your control flow. That is a feature: you decide the order, the retries, and the stopping condition.Navigate first
Don’t put navigation inside an instruction. Handle it separately withgoto.
- TypeScript
- Python
- Go
Break work into steps
One instruction per action. Sequence them yourself so each step is independently debuggable and cacheable.- TypeScript
- Python
- Go
Include success criteria
Verify each step landed instead of assuming it did.- TypeScript
- Python
- Go
Common mistakes to avoid
- Combining multiple actions: Keep each
act()call to one action - Using vague descriptions: Be specific about which elements to interact with
- Exposing sensitive data: Always use variables for credentials
- Skipping validation: Check results before proceeding
Testing your prompts
- Start simple: Test basic functionality first
- Add complexity gradually: Build up to complex workflows
- Monitor results: Use logging to understand what’s happening
- Iterate based on failures: Refine prompts when they don’t work

