fix: stricter field validation for human input requests (#184 feedback)

Validate select option structure (value/label keys, non-empty strings)
and reject options on non-select field types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Caitlyn Byrne
2026-02-14 07:44:30 -05:00
parent 69d9313c07
commit d712e58ff5

View File

@@ -1049,8 +1049,21 @@ def feature_request_human_input(
ftype = field.get("type", "text")
if ftype not in VALID_FIELD_TYPES:
return json.dumps({"error": f"Field at index {i} has invalid type '{ftype}'. Must be one of: {', '.join(sorted(VALID_FIELD_TYPES))}"})
if ftype == "select" and not field.get("options"):
return json.dumps({"error": f"Field at index {i} is type 'select' but missing 'options' array"})
if ftype == "select":
options = field.get("options")
if not options or not isinstance(options, list):
return json.dumps({"error": f"Field at index {i} is type 'select' but missing or invalid 'options' array"})
for j, opt in enumerate(options):
if not isinstance(opt, dict):
return json.dumps({"error": f"Field at index {i}, option {j} must be an object with 'value' and 'label'"})
if "value" not in opt or "label" not in opt:
return json.dumps({"error": f"Field at index {i}, option {j} missing required 'value' or 'label'"})
if not isinstance(opt["value"], str) or not opt["value"].strip():
return json.dumps({"error": f"Field at index {i}, option {j} has empty or invalid 'value'"})
if not isinstance(opt["label"], str) or not opt["label"].strip():
return json.dumps({"error": f"Field at index {i}, option {j} has empty or invalid 'label'"})
elif field.get("options"):
return json.dumps({"error": f"Field at index {i} has 'options' but type is '{ftype}' (only 'select' uses options)"})
request_data = {
"prompt": prompt,