Enhance JSON schema validation with contextual suggestions for fixes#1045
Merged
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Generate field suggestions for unexpected properties - Show example JSON for type errors - Handle oneOf schemas correctly - Add comprehensive tests for suggestion functionality Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ions - Extract hardcoded values as named constants for better maintainability - Add early return for empty invalidProps parameter - Optimize similarity scoring with early exit for poor matches - All tests pass and functionality remains intact Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
Update the rendering of json schema validation by providing suggestions for fixes based on the schema.
- if a field name is unexpected, suggest accept fields
- if the wrong object type is provided, show example of correct JSON (generated on the fly fr...
Enhance JSON schema validation with contextual suggestions for fixes
Sep 26, 2025
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.
This PR significantly improves the developer experience when encountering JSON schema validation errors by providing contextual suggestions for fixes.
Problem
Previously, schema validation errors provided only generic messages that didn't help users understand what valid alternatives were available:
This made it difficult for users to quickly fix validation errors, especially when dealing with typos or unfamiliar properties in complex nested configurations.
Solution
The validation system now analyzes the JSON schema to provide intelligent suggestions:
Field Name Suggestions
When users provide invalid property names, the system extracts valid field names from the schema and suggests close matches:
Type Error Examples
When the wrong data type is provided, the system generates example JSON showing the correct format:
Multiple Error Handling
The system can handle multiple validation errors and provide comprehensive suggestions:
Key Features
Technical Implementation
The implementation adds several new functions to
pkg/parser/schema.go:generateSchemaBasedSuggestions(): Main entry point for generating contextual suggestionsextractAcceptedFieldsFromSchema(): Navigates JSON schema to find valid propertiesgenerateFieldSuggestions(): Creates human-readable field suggestions with similarity matchinggenerateExampleJSONForPath(): Generates example JSON objects from schema definitionsresolveSchemaWithOneOf(): Handles complex oneOf schema patterns correctlyAll magic numbers have been extracted as named constants, and comprehensive test coverage ensures reliability across different validation scenarios.
Impact
This change transforms validation errors from cryptic messages into actionable guidance, significantly reducing the time developers spend debugging configuration issues in agentic workflows.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.