Good prompts make Stagehand reliable. Bad prompts cause failures. Here’s how to write prompts that work consistently.
Act Method
Use act() for single actions on web pages. Each action should be focused and clear.
Use Element Types, Not Colors
Describe elements by their type and function rather than visual attributes like color.
Use Descriptive Language
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
Protect Sensitive Data
Variables keep sensitive information out of prompts and logs.
Set verbose: 0 in your Stagehand config to prevent secrets from appearing in logs.
Use extract() 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 agent understand exactly what to extract.
Handle Arrays Correctly
Always wrap schemas in objects for reliable extraction.
Use Proper URL Types
Specify URL types to tell Stagehand to extract URLs. Without proper URL types, Stagehand won’t extract URLs.
Observe Method
Use observe() to discover actionable elements before acting on them.
Check Elements First
Verify elements exist before taking action to avoid errors.
Be Specific About Element Types
Agent Method
Use agent() for complex, multi-step workflows. Provide detailed instructions and set appropriate limits.
Navigate First
Don’t include navigation in agent tasks. Handle it separately.
Be Highly Specific
Detailed instructions lead to better results.
Set Appropriate Step Limits
Match step limits to task complexity.
Include Success Criteria
Tell the agent how to know when it’s done.
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
Remember: Good prompting is iterative. When in doubt, be more specific rather than less.