Add validate_expression_tool for Mapbox expression validation#51
Merged
mattpodwysocki merged 2 commits intomainfrom Jan 12, 2026
Merged
Add validate_expression_tool for Mapbox expression validation#51mattpodwysocki merged 2 commits intomainfrom
mattpodwysocki merged 2 commits intomainfrom
Conversation
This commit adds a comprehensive Mapbox expression validation tool that performs offline validation of style expressions without requiring API access. Features: - Validates all Mapbox expression operators (90+ operators supported) - Checks expression syntax (array format, string operators) - Validates argument counts for each operator - Recursive validation of nested expressions - Detects and warns about deeply nested expressions (depth > 10) - Returns structured errors, warnings, and info messages with suggestions - Provides metadata (expressionType, returnType, depth) - Accepts both JSON strings and expression arrays as input Supported operator categories: - Decision: case, match, coalesce - Lookup: get, has, in, index-of, length - Math: +, -, *, /, %, ^, min, max, round, floor, ceil, abs, sqrt, log10, log2, ln, e, pi - Comparison: ==, !=, >, <, >=, <= - Logical: !, all, any - String: concat, downcase, upcase - Color: rgb, rgba, to-rgba - Type conversion: array, boolean, number, string, to-boolean, to-color, to-number, to-string, typeof - Interpolation: interpolate, step - Feature data: get, has, feature-state, geometry-type, id, properties - Camera: zoom, pitch, distance-from-center - Variable binding: let, var The tool is implemented as a BaseTool (offline, no HttpRequest dependency) and includes 25 comprehensive test cases covering literals, valid expressions, invalid expressions, nested expressions, error handling, and metadata. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This was referenced Jan 8, 2026
mattpodwysocki
added a commit
that referenced
this pull request
Jan 9, 2026
…roduction prompt Adds comprehensive style quality validation capabilities: Skill: - Created mapbox-style-quality skill document (390+ lines) - Pre-production checklist and validation best practices - Guidance on expression validation, GeoJSON validation, and accessibility - Optimization strategies and workflow recommendations - Integration patterns for Git hooks, CI/CD, and code review Prompt: - Created prepare-style-for-production prompt - Orchestrates validation workflow using 5 quality tools: * validate_expression_tool - Validate expressions in filters/paint/layout * validate_geojson_tool - Validate GeoJSON sources * check_color_contrast_tool - WCAG accessibility compliance * optimize_style_tool - Remove redundancies and optimize * compare_styles_tool - Compare versions (implicit in workflow) - Configurable WCAG level (AA/AAA) and optional optimization skip - Generates comprehensive quality report with deployment readiness assessment Testing: - 15 test cases for PrepareStyleForProductionPrompt - All 386 tests passing - Updated prompt registry tests Documentation: - Updated README with new skill listing - Added prompt documentation with usage examples - Cross-referenced skill and prompt Related PRs: - PR #50: validate_geojson_tool - PR #51: validate_expression_tool - PR #52: compare_styles_tool - PR #53: check_color_contrast_tool - PR #54: optimize_style_tool Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Valiunia
previously approved these changes
Jan 12, 2026
Valiunia
approved these changes
Jan 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a comprehensive offline Mapbox expression validation tool that checks style expressions for correctness without requiring API access.
Features
✅ Validates 90+ Mapbox expression operators:
✅ Comprehensive validation checks:
✅ Structured validation results:
validboolean flagerrorsarray (critical issues)warningsarray (non-critical issues like deep nesting)infoarray (informational messages)metadataobject (expressionType, returnType, depth)✅ Developer-friendly:
Implementation Details
BaseTool(offline, no HttpRequest dependency)Test Results
All 395 tests pass ✅
Example Usage
{ "expression": ["case", ["==", ["get", "type"], "park"], "green", "gray"] }Returns:
{ "valid": true, "errors": [], "warnings": [], "info": [], "metadata": { "expressionType": "case", "depth": 1 } }Error Example
{ "expression": ["unknown_operator", "value"] }Returns:
{ "valid": false, "errors": [ { "severity": "error", "message": "Unknown expression operator: \"unknown_operator\"", "path": "[0]", "suggestion": "Use a valid Mapbox expression operator (e.g., \"get\", \"case\", \"match\")" } ] }Testing
Test 1: Valid Simple Expression ✅
Validate this Mapbox expression:
Expected: Valid - gets the "name" property from a feature
Test 2: Valid Conditional Expression ✅
Can you validate this expression?
Expected: Valid - conditional styling based on feature type
Test 3: Valid Math Expression ✅
Validate this:
Expected: Valid - multiplies population by 0.001
Test 4: Invalid Operator ❌
Check this expression:
Expected:
Test 5: Wrong Argument Count ❌
Is this valid?
Expected:
Test 6: Valid Interpolation Expression ✅
Validate this interpolation:
Expected: Valid - interpolates circle radius based on zoom level
Test 7: Nested Expression with Error ❌
Check this nested expression:
Expected:
Test 8: Valid String Expression ✅
Validate:
Expected: Valid - concatenates strings for labels
Test 9: Valid Color Expression ✅
Is this valid?
Expected: Valid - creates RGB color
Test 10: Complex Valid Expression ✅
Validate this complex expression:
Expected: Valid - data-driven color based on population with exponential interpolation
Related
Part of a series of offline validation tools being added to the server: