Skip to content
23 changes: 16 additions & 7 deletions velvetflow/verification/binding_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def _index_actions_by_id(action_registry: List[Dict[str, Any]]) -> Dict[str, Dic
return {a["action_id"]: a for a in action_registry}


def _coerce_out_param_schema(value: Any) -> Mapping[str, Any]:
if isinstance(value, Mapping):
if any(key in value for key in ("type", "properties", "$schema")):
return value
properties = {key: _coerce_out_param_schema(item) for key, item in value.items()}
return {"type": "object", "properties": properties}
Comment on lines +26 to +31
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat non-type schema keywords as schemas, not objects

The new _coerce_out_param_schema treats any mapping that lacks type/properties/$schema as a nested object map, which changes the previous behavior for field-level schemas that only use other JSON Schema keywords (e.g., {"enum": [...]}, {"oneOf": [...]}, {"items": {...}}). Those were previously passed through as-is, but now get coerced into {type: object, properties: {enum: ...}}, so reference validation will interpret foo.enum as a property instead of applying the schema to foo. This breaks existing out_params_schema definitions that rely on keyword-only schemas; consider broadening the “already a schema” check to include other JSON Schema keywords.

Useful? React with 👍 / 👎.


if isinstance(value, str):
return {"type": value}

return {}


def _schema_from_out_params_schema(
out_params_schema: Mapping[str, Any] | None,
) -> Optional[Mapping[str, Any]]:
Expand All @@ -35,13 +48,9 @@ def _schema_from_out_params_schema(
if any(key in out_params_schema for key in ("type", "properties", "$schema")):
return out_params_schema

properties: Dict[str, Any] = {}
for key, value in out_params_schema.items():
if isinstance(value, Mapping):
properties[key] = value
else:
# Best-effort wrapper when only scalar types are provided.
properties[key] = {"type": value} if isinstance(value, str) else {}
properties: Dict[str, Any] = {
key: _coerce_out_param_schema(value) for key, value in out_params_schema.items()
}

return {"type": "object", "properties": properties}

Expand Down
Loading