feat(logic-grid-ai)!: structured validation errors + model option#23
Merged
antonstefer merged 2 commits intoApr 28, 2026
Merged
Conversation
Three small AI-package improvements bundled into one major bump.
1. Validation returns structured errors instead of plain strings.
- validateThemeResult now returns ThemeValidationError[] (each with a
stable code, human-readable message, and optional category field).
- validateRewrittenClues now returns RewriteCluesValidationError[]
(with code, message, optional 1-indexed clueIndex).
- Codes are exported as union types so callers can do exhaustive
switches.
- generateTheme now throws ThemeGenerationError carrying the
structured errors; rewriteClues throws RewriteCluesError likewise.
Callers can branch on err.errors[i].code to surface specific UI
hints (e.g. "no_ordered_category" → guide the user to add one).
2. createAnthropicClient(apiKey?, options?) accepts an optional model
override. Defaults to the existing claude-sonnet-4-6. Useful for
swapping to claude-haiku-4-5 for cheaper/faster generation without
writing a whole custom AIClient.
3. Documents that transport-level retries (429s, 5xx, network) are
already handled inside the Anthropic SDK with exponential backoff.
Our retry loop only covers semantic validation failures.
Tests updated to assert on stable error codes rather than message
substrings; coverage stays at 100% across all metrics.
BREAKING CHANGE: validateThemeResult and validateRewrittenClues now
return structured ValidationError objects instead of strings. Migration:
read e.message for the human-readable text (same content as before), or
switch to e.code for stable, machine-readable identifiers. generateTheme
and rewriteClues now throw ThemeGenerationError / RewriteCluesError
subclasses instead of plain Error; existing instanceof Error checks
still match.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
logic-grid | 89eae4f | Commit Preview URL Branch Preview URL |
Apr 28 2026, 01:18 PM |
- Lift duplicated hasCode helper into src/test-utils.ts (typed generically so passing a foreign code still fails type-check at the call site). - Document on ThemeValidationError that the category field echoes the asserted name even when the name itself is what's invalid (e.g. for long_category_name) — preserves grouping by category in callers. - Skip the duplicate-name check when the asserted name is empty, so two categories with empty names report two empty_category_name errors rather than empty + duplicate. The empty name is the problem; calling it a duplicate of another empty name is noise. Added a covering test.
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
Three small AI-package improvements bundled into one major bump.
1. Structured validation errors
validateThemeResultnow returnsThemeValidationError[](each with a stablecode, human-readablemessage, and optionalcategoryfield).validateRewrittenCluesreturnsRewriteCluesValidationError[]withcode,message, optional 1-indexedclueIndex. Codes are exported as union types so callers can write exhaustive switches.generateThemenow throwsThemeGenerationErrorcarrying the structured errors;rewriteCluesthrowsRewriteCluesError. Callers can do:2. Model option on
createAnthropicClientDefaults to the existing
claude-sonnet-4-6. Backward-compatible — old single-arg call sites still work. Useful for swapping to Haiku for cheaper/faster generation without writing a whole customAIClient.3. Documents Anthropic SDK retry behavior
Code comment + README note: transport-level retries (429s, 5xx, network errors) are already handled inside the Anthropic SDK with exponential backoff. Our
MAX_RETRIES = 3only covers semantic validation failures (the AI returned malformed output and we re-prompt with the errors). The two layers don't compound.Coverage
logic-grid-aistays at 100% statements / branches / functions / lines (75 tests).Breaking changes
validateThemeResultandvalidateRewrittenCluesreturn structured objects instead of strings.e.messagefor the same human-readable text, or switch toe.codefor stable identifiers.generateThemeandrewriteCluesnow throwThemeGenerationError/RewriteCluesErrorsubclasses instead of plainError.instanceof Errorchecks still match — only===againstErroritself would change behavior.Release impact
feat!:triggers a major bump → release-please will propose logic-grid-ai 2.0.0. Worth merging together with the in-flightlogic-grid 3.0.0Release PR (#22) since logic-grid-ai's peerDep on logic-grid is also moving up.