Replies: 2 comments 11 replies
-
I'm not sure I understand what you're suggesting. Can you edit your post to include an example of what you're looking for? |
Beta Was this translation helpful? Give feedback.
10 replies
-
I'm not sure this is what you're looking for exactly, and it's not Python, so you probably can't use it anyway, but ... My implementation uses a JSON AST that includes errors and annotations that apply to each node based on validation. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
UPDATED
Hi everyone,
I've recently been using JSON Schema and its validation mechanisms in Python for language modeling. During this process, I noticed that there doesn't seem to be any tooling or implementation that can help build an Abstract Syntax Tree (AST)-like construct from the matched input instance.
Having such a tool would be incredibly valuable because I've observed that, especially with complex or recursive schemas, it's possible to have incorrect validations (false positives) that are silently accepted. This can lead to significant issues, particularly when the validation doesn't align with the intended logic.
I'm not sure if anyone else has experimented with this idea, but I'd like to bring it to the community's attention. I'm also interested in contributing to the implementation or standardization of such an extension or approach.
To clarify, let's consider an example where I'm implementing a templating language similar to JSON Logic I might write a schema like the following (note that this is incomplete, with irrelevant fields omitted):
Now, consider an input like this:
In this case, the input is silently validated as correct under the schema, even though there is an unintended space before "and". While the validator might consider this a true positive according to the schema's rules, it is a false positive in the context of my intended logic.
If I could obtain the validation result in the form of an AST, I could more easily debug and determine whether the "match" was a false positive. The AST would provide a clearer view of the validation path, making it easier to spot mismatches between the expected and actual input structure.
For an example like
The json representation of the AST would look like
or
The Root node represents the entire input structure.
The AndExpression node represents the "and" operation at the first level of the array.
Each BooleanLiteral node corresponds to a true value in the input.
The NotExpression nodes represent the "not" operations.
This AST clearly shows the structure and relationships within the input, making it easier to see whether the input conforms to the intended logic. For instance, if a validation issue arises, you could trace through this tree to see where the input deviates from the expected pattern.
If I could obtain the validation result in the form of an AST like this, it would be much easier to debug and determine whether a validation outcome was truly intended or a false positive.
for instance with the schema
will produce "false positive" validation.
I hope this explanation is clear, and I'd love to hear your thoughts or see if anyone is interested in exploring this concept further.
Beta Was this translation helpful? Give feedback.
All reactions