Skip to content

fix(agent): enforce JSON Schema dict validation and forward validated HITL outputs - #45

Open
alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796091612-enforce-tool-schemas
Open

alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1796091612-enforce-tool-schemas

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes two schema-enforcement gaps in tool input and HITL output handling:

  1. Plain JSON Schema dict validation (src/openrouter_agent/_utils.py): validate_schema previously fell through and returned value unvalidated whenever schema was a plain JSON Schema dict, allowing model-supplied arguments that violate the advertised schema to execute. Plain dict schemas are now sanitized and validated with jsonschema (validator_for(cleaned) + check_schema + validate) before tool execution and approval predicate evaluation.
  2. HITL output_schema forwarding (src/openrouter_agent/tool_executor.py): In apply_on_response_received_hooks, when no on_response_received hook was configured, validate_schema(output_schema, raw) ran but discarded its return value and appended original unchanged, forwarding extra fields that Pydantic or a custom validator stripped. The validated output is now serialized (validated if is_content_array(validated) else json_dumps(validated)) and written back to the item's output while preserving the rest of the item shape.

Testing

  • Added unit tests in tests/unit/test_schema_enforcement.py covering JSON Schema dict validation (regular, generator, HITL tools, approval predicates, malformed schemas, and call_model turns) and HITL output_schema stripping/forwarding with and without on_response_received hooks.
  • Ran ./.upstreamer/scripts/verify.sh (uv sync, uv lock --check, ruff check, ruff format --check, mypy src tests, pytest tests/unit --cov --cov-fail-under=83).
@devin-ai-integration

devin-ai-integration Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant