Describe the Bug
Enum validation only works for top-level parameters. Enum constraints inside nested object properties are NOT validated at runtime, allowing invalid values to pass through.
To Reproduce
Steps to reproduce the behavior:
- Create a tool with a nested object parameter containing an enum field
- Run the tool with an invalid value for the nested enum
- Observe that no validation error is raised
mxcp run tool test --param preferences='{"theme":"invalid"}'
# Result: Succeeds with "invalid" - no validation error
Expected Behavior
Nested enum values should be validated at runtime, and invalid values should raise a ValidationError with a message like: "Value must be one of: ['light', 'dark', 'auto']".
Environment
- MXCP Version: latest from pip
- Python Version: 3.11+
- Operating System: Any
- Installation Method: pip
Configuration
parameters:
- name: preferences
type: object
properties:
theme:
type: string
enum: ["light", "dark", "auto"]
Error Output
No error is raised - this is the bug. The invalid value "invalid" is accepted.
Additional Context
Root Cause Analysis:
Enum validation is done in core.py:84-88 at the top-level parameter loop only:
# core.py:82-88
param_schema = param_lookup[name]
# Check enum values first
if param_schema.enum is not None and value not in param_schema.enum:
raise ValidationError(
f"Invalid value for {name}. Must be one of: {param_schema.enum}"
)
# Convert and validate the parameter
validated[name] = TypeConverter.convert_parameter(value, param_schema)
The issue is that:
- Enum validation happens BEFORE
convert_parameter is called
convert_parameter in converters.py handles nested objects recursively but DOES NOT check enum constraints
- There's no enum validation code in
converters.py at all
Fix Required:
Add enum validation in converters.py within the string/number/integer type handlers:
# Add to string/number/integer handling in convert_parameter
if schema.enum is not None and value not in schema.enum:
raise ValidationError(f"Value must be one of: {schema.enum}")
Location in code:
core.py:84-88 - Top-level validation (works)
converters.py - Missing nested enum validation
Note: Top-level enum validation DOES work correctly. Only nested enums inside object properties are affected.
This happens consistently when using nested enum fields.
Describe the Bug
Enum validation only works for top-level parameters. Enum constraints inside nested object properties are NOT validated at runtime, allowing invalid values to pass through.
To Reproduce
Steps to reproduce the behavior:
Expected Behavior
Nested enum values should be validated at runtime, and invalid values should raise a
ValidationErrorwith a message like:"Value must be one of: ['light', 'dark', 'auto']".Environment
Configuration
Error Output
Additional Context
Root Cause Analysis:
Enum validation is done in
core.py:84-88at the top-level parameter loop only:The issue is that:
convert_parameteris calledconvert_parameterinconverters.pyhandles nested objects recursively but DOES NOT check enum constraintsconverters.pyat allFix Required:
Add enum validation in
converters.pywithin the string/number/integer type handlers:Location in code:
core.py:84-88- Top-level validation (works)converters.py- Missing nested enum validationNote: Top-level enum validation DOES work correctly. Only nested enums inside object properties are affected.
This happens consistently when using nested enum fields.