#20567: fix: validate model IDs against catalog before saving to config
commands
size: M
Cluster:
Wizard Enhancements and Config Fixes
## Summary
Adds config-time validation for model IDs set via `openclaw models set` and `openclaw models set-image`. Previously, invalid model IDs were silently accepted and only failed at runtime with cryptic errors.
Fixes #20522
## Changes
- **New file: `validate-model.ts`** — `validateModelAgainstCatalog()` checks model IDs against the available model catalog before saving to config
- **Updated: `set.ts` / `set-image.ts`** — Now validate before writing config
- **New file: `validate-model.test.ts`** — 9 test cases covering valid models, invalid models, fuzzy suggestions, case insensitivity, cross-provider suggestions, empty catalog fallback, and catalog load failure graceful handling
## How it works
1. Parses the model reference (provider/model)
2. Loads the model catalog
3. Checks for exact match (case-insensitive)
4. If no match: uses Levenshtein distance for fuzzy "Did you mean?" suggestions
5. Suggests `openclaw models list` to see available models
6. Gracefully allows through when catalog is unavailable (no auth configured yet)
## Example output
```
$ openclaw models set amazon-bedrock/us.anthropic.claude-opus-4-6-v1:0
Model "amazon-bedrock/us.anthropic.claude-opus-4-6-v1:0" not found in the available model catalog.
Did you mean one of these?
- anthropic/claude-opus-4-6
- anthropic/claude-opus-4-5
Run openclaw models list to see all available models.
```
## Testing
- 9 unit tests, all passing
- Build passes (`pnpm build`)
- Lint passes (eslint)
- Existing `models/shared.test.ts` tests still pass
## AI Disclosure
This PR was AI-assisted (built by an OpenClaw agent running on the platform). Code reviewed and approved by human. We understand what the code does.
Co-authored-by: Claw <midnightclawbot@agentmail.to>
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added validation for model IDs in `openclaw models set` and `openclaw models set-image` commands to prevent invalid model IDs from being saved to config. The validation checks against the available model catalog and provides helpful error messages with fuzzy suggestions using Levenshtein distance.
**Key changes:**
- New `validateModelAgainstCatalog()` function performs case-insensitive catalog lookup with fuzzy matching
- Gracefully handles cases where catalog is unavailable (no auth configured)
- Integration into both `set.ts` and `set-image.ts` commands validates before config write
- Comprehensive test coverage with 9 test cases covering valid/invalid models, case insensitivity, cross-provider suggestions, and error handling
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minor considerations
- The implementation is well-structured with comprehensive test coverage (9 test cases) and handles edge cases gracefully (empty catalog, catalog load failures). The validation logic is sound, using case-insensitive matching and fuzzy suggestions. The integration is minimal and straightforward. One minor consideration is the potential for case inconsistency in returned keys, though this is likely handled correctly by existing code expecting catalog-casing.
- No files require special attention
<sub>Last reviewed commit: b8718ec</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9064: fix: validate model references against catalog in config.set/patch/...
by joetomasone · 2026-02-04
82.7%
#18697: fix: include forward-compat models in model catalog for allowlist val…
by dmitry-orabey · 2026-02-17
76.5%
#16988: fix: always regenerate models.json from gateway config
by MisterGuy420 · 2026-02-15
76.0%
#9583: fix(models): allow models in agents.defaults.models even if not in ...
by hotzen100 · 2026-02-05
75.1%
#19020: bugfix(gateway): Handle invalid model provider API config gracefully\…
by funkyjonx · 2026-02-17
74.7%
#21638: fix(models): surface models.json validation errors instead of faili...
by aldoeliacim · 2026-02-20
74.4%
#18988: feat(config): add support for config warnings and improve validation
by saurav470 · 2026-02-17
74.3%
#21963: fix(cli): models fallbacks add now includes primary model in allowlist
by ashiabbott · 2026-02-20
74.3%
#4459: fix: enable image input for Kimi K2.5 and refresh stale config mode...
by manikv12 · 2026-01-30
74.1%
#6673: fix: preserve allowAny flag in createModelSelectionState for custom...
by tenor0 · 2026-02-01
74.1%