Nested Schema Validation & Type mismatch check#729
Open
AbhinRustagi wants to merge 36 commits into
Open
Conversation
AbhinRustagi
marked this pull request as ready for review
July 9, 2026 04:53
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.
Schema validation for component props: validate, repair, and prune instead of drop-or-ignore
What this PR does
Previously the parser only checked that required top-level props were present — nested data was never validated, and a wrong-typed value flowed straight to the renderer. This PR adds recursive JSON-Schema validation of all component props (objects, arrays, scalar/enum leaves, and component elements in data positions), and applies one consistent resolution rule to every invalid value instead of either ignoring it or blanking the UI:
At the outermost edge (component param), "propagate" means drop the component. Net effect: a deep violation can only blank the root if every edge on the path is required and none is an array item — i.e. only when the tree genuinely cannot satisfy the schema. LLM output degrades gracefully; the error always reaches the host's
onErrorfor the correction loop.Cases covered
missing-required/null-required) + parent invalidtype-mismatch→ resolution ruletype-mismatch→ resolution ruleHorizontalBarChart(Card([]), …))type-mismatch("expects array but got component Card") → resolution rule$ref/anyOf)Badge("primcut mid-token)$ref/anyOf/oneOf/allOf) for plain values$var, builtins)type, tupleitems, non-arrayrequired)defaultvalues themselvesError reporting
type-mismatcherror code,expects X but got Yshape everywhere (incl. enum lists:expects one of ["info", …] but got "inf").ValidationIssue→validationMessage) — no per-call-site drift. Note: top-level missing-required messages now use JSON-pointer paths ("/theme"instead of"theme"); match on.code/.path, not message text.… — signature: Callout(variant*: "info"|"warning"|…, title*: string, …)); unknown components inline the full catalog (… Available components: Card, TextContent, …).enrichErrorsis deprecated (unchanged otherwise — reverted to itsmainbehavior). SinceValidationError.messagenow carries everything the hints did, consumers should readresult.meta.errorsdirectly — match on.code/.path, display.message. The pass keeps working during the transition and will be removed in a future major.Implementation notes
validation.ts(new): shape-dispatched validators (validateElementPosition/Object/Array/Leaf) + sharedresolveInvalidValueedge rule + issue-based error reporting.materialize.tsapplies the same edge rule at the param boundary;MaterializeCtxmoved totypes.tsto break the import cycle.Obj/Arrmaterialize fresh per parse; the streaming parser's cached AST is never touched.compileSchemaretains each param's schema fragment (ParamDef.schema), low-level parsing pipeline exports (tokenize,parseExpression,split,autoClose,walkAST,Token), and a prompt rule requiring filter$bindingsto appear in Query args.Deferred (explicit non-goals here)
$refresolution — data behind$ref(e.g. chartSeries) is still unchecked; biggest coverage gap, planned next.partial(checks currently gate on whole-document completeness);additionalProperties; constraint keywords (minItems,pattern, …).Tests
20 consolidated cases in
materialize.validation.test.ts, one per behavior family: recursive descent & reporting, the edge rule (each row of the table above), components in data slots, conservative skips, streaming gates. Full suite: 98/98.