Validate Preset String • AI Agent SDK

validate_preset_string: Raise a helpful error when a string does not name a known preset.

validate_preset_string

Function

</div>

This function is defined in the parse_utils module.

Raise a helpful error when a string does not name a known preset.

Non-string values pass through untouched, so callers can hand this the raw parameter without pre-checking the type. Matching is case-insensitive, ignores surrounding whitespace, and treats `-/_ as interchangeable, mirroring the preset lookups performed by the parameter resolvers (e.g. PermissionMode.resolve accepts both accept_edits and accept-edits`). This keeps the guard from rejecting spellings the downstream resolver would happily accept.

Signature

python
def validate_preset_string(param_name: str, value: Any, presets: Iterable[str]) -> None

Parameters

ParamField str

Name of the parameter (for the error message)

ParamField Any

Raw parameter value

ParamField Iterable[str]

Valid preset names

Exceptions

ValueError

If value is a string that is not a known preset

Uses

  • canonical_preset_key
  • make_preset_error

Source

View on GitHub

praisonaiagents/config/parse_utils.py at line 209