Skip to content

fix: wrap call_service_tool response in dict to fix Pydantic validation#36

Open
brianegge wants to merge 1 commit intovoska:masterfrom
brianegge:fix/call-service-tool-return-type
Open

fix: wrap call_service_tool response in dict to fix Pydantic validation#36
brianegge wants to merge 1 commit intovoska:masterfrom
brianegge:fix/call-service-tool-return-type

Conversation

@brianegge
Copy link
Copy Markdown

Summary

Fixes #29

The Home Assistant API returns a list of affected entity states for service calls (e.g., [] for automation.reload), but call_service_tool was passing this list directly as its return value. Since the function's return type annotation is Dict[str, Any], this caused Pydantic validation errors:

Error executing tool call_service_tool: 1 validation error for call_service_toolOutput
result
  Input should be a valid dictionary [type=dict_type, input_value=[], input_type=list]

Changes

  • app/hass.py: Fix call_service return type annotation from Dict[str, Any] to List[Dict[str, Any]] to reflect actual HA API behavior
  • app/server.py: Wrap call_service_tool result in a dict with success, domain, service, and affected_entities fields
  • tests/test_server.py: Add regression tests for the fix

New Response Format

Before:

[]  # Raw list from HA API - causes validation error

After:

{
    "success": True,
    "domain": "automation",
    "service": "reload",
    "affected_entities": []
}

Test Plan

  • Added test_call_service_tool_returns_dict - verifies the tool always returns a dict
  • Added test_call_service_tool_with_data - verifies data is passed correctly
  • All existing tests pass

🤖 Generated with Claude Code

The Home Assistant API returns a list of affected entity states for service
calls, but call_service_tool was passing this list directly as its return
value. Since the function's return type is Dict[str, Any], this caused
Pydantic validation errors when calling services like automation.reload
that return empty lists.

Changes:
- Fix call_service return type annotation in hass.py to List[Dict[str, Any]]
- Wrap call_service_tool result in a dict with success, domain, service,
  and affected_entities fields
- Add regression tests for the fix

Fixes voska#29

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The return from the call_service_tool is problematic; it is not in dictionary format, causing the large model to report an error.

1 participant