What Are Query Shapes?
Query shapes represent patterns in the types of queries executed by your MCP tools. They show you how agents are interacting with your data—what filters they use, what parameters they pass, and what patterns emerge.Why Query Shapes Matter
Understanding query shapes helps you:- ✅ Optimize Queries: See what queries are most common
- ✅ Improve Tools: Understand how agents actually use your tools
- ✅ Identify Patterns: Find common query patterns
- ✅ Optimize Performance: Focus optimization on frequent patterns
- ✅ Enhance Tools: Add tools for common query patterns
Query shapes reveal the real-world usage patterns of your tools. They show you what agents actually need, not just what you thought they would need.
Accessing Query Shapes
In the Evaluation Dashboard:- Select the tool you want to analyze
- Scroll to the Error Analysis section
- Find the Query Shape section
- Review the query patterns displayed
Understanding Query Patterns
Common Query Patterns
Query shapes show patterns like:- Simple Filters: Queries with single WHERE conditions
- Date Ranges: Queries filtering by date ranges
- Multiple Filters: Queries with multiple WHERE conditions
- Aggregations: Queries with GROUP BY or aggregations
- Sorting Patterns: How results are ordered
Example Query Shapes
Pattern 1: Single FilterAnalyzing Query Shapes
What to Look For
- Most Common Patterns: What queries are executed most frequently?
- Parameter Usage: Which parameters are used most often?
- Filter Combinations: What combinations of filters appear?
- Sort Patterns: How are results typically ordered?
Identifying Optimization Opportunities
High-frequency patterns indicate optimization opportunities:- Add Indexes: If certain filters are common, ensure indexes exist
- Create Specialized Tools: If a pattern is frequent, consider a dedicated tool
- Optimize Queries: Focus performance improvements on common patterns
- Simplify Tools: If agents always use specific parameters, make them defaults
If a query pattern appears frequently (30%+ of queries), consider creating a dedicated tool optimized for that pattern. This can improve performance and agent experience.
Using Query Shapes to Improve Tools
Scenario 1: Common Filter Pattern
Observation: 60% of queries filter byevent_type
Action:
- Ensure
event_typefiltering is optimized - Consider making
event_typea required parameter - Add tool description emphasizing event_type filtering
Scenario 2: Date Range Pattern
Observation: Many queries use date ranges Action:- Create a dedicated tool for date range queries
- Add date range parameters to existing tools
- Optimize date filtering in queries
Scenario 3: Multiple Parameter Combinations
Observation: Agents frequently combine specific parameters Action:- Create tools optimized for common combinations
- Add default values for frequently used parameters
- Update tool descriptions to highlight common use cases
Query Shape Examples
Example 1: Engagement Score Queries
Common Pattern:- Agents always filter by event_type
- Always sorted by engagement_score descending
- Uses LIKE pattern matching
- Make event_type a required parameter
- Consider exact match instead of LIKE if pattern is consistent
- Add LIMIT if results are always large
Example 2: Date Range Queries
Common Pattern:- Always uses date range filtering
- Always sorted by date
- Returns all columns
- Create dedicated date range tool
- Add default date range (e.g., last 30 days)
- Consider selecting specific columns instead of *
Example 3: Multi-Filter Queries
Common Pattern:- Always combines region, status, and revenue filters
- Revenue threshold is common
- Create tool specifically for this combination
- Make min_revenue optional with default
- Add indexes on region, status, revenue columns
Best Practices
Regular Review
- ✅ Review query shapes weekly
- ✅ Look for new patterns emerging
- ✅ Identify optimization opportunities
- ✅ Track changes over time
Pattern Documentation
- Document common query patterns
- Note which patterns are most frequent
- Track how patterns change over time
- Share insights with team
Optimization Strategy
- Identify high-frequency patterns (30%+ of queries)
- Analyze if patterns can be optimized
- Create specialized tools for common patterns
- Monitor if optimizations improve performance
Using Query Shapes with Raw Logs
Combine query shapes with raw logs for deeper insights:- Identify a pattern from Query Shapes
- Go to Raw Logs
- Filter for queries matching that pattern
- Analyze specific examples
- Understand how agents use that pattern
Query shapes give you the big picture, while raw logs give you the details. Use both together for comprehensive analysis.
Next Steps
Now that you understand query shapes:- Understanding Query Logs - Dive into detailed execution logs
- Improving Tools with Evals - Use query shape insights to optimize tools
- Improving Views with Evals - Optimize views based on query patterns
Explore Raw Logs
Learn how to analyze detailed query logs