You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: harden ha_config_set_yaml description and require justification
LLM agents routinely reach for ha_config_set_yaml to create trigger-based
template sensors even though ha_set_config_entry_helper (domain=template)
supports them natively. The previous description listed
ha_config_set_helper as the preferred alternative for template sensors,
but ha_config_set_helper's helper_type enum does not include 'template' —
so an agent that tried to follow the guidance would hit a schema error
and then fall back to raw YAML editing.
This change:
- Reframes the docstring and tool title as an escape hatch. The first
sentence now warns instead of welcoming, and the dedicated-tool
preference list is the first thing a model sees.
- Points template sensors (state-based AND trigger-based) at the
correct tool, ha_set_config_entry_helper with helper_type='template',
which does support triggers via the config entry flow.
- Hardens the yaml_path parameter description with per-key warnings, so
the nudge survives context compression even when the full docstring
is trimmed by the client.
- Adds a required justification parameter (mirroring the pattern from
ha_manage_custom_tool in homeassistant-ai#854). Justification is validated non-empty,
logged, and exists purely as friction — the goal is to make an agent
pause and articulate why no dedicated tool fits before reaching for
the escape hatch.
Ref: discussion homeassistant-ai#936
Copy file name to clipboardExpand all lines: site/src/data/tools.json
+7-3Lines changed: 7 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2414,16 +2414,20 @@
2414
2414
},
2415
2415
{
2416
2416
"name": "ha_config_set_yaml",
2417
-
"title": "Set YAML Config",
2418
-
"description": "Add, replace, or remove a top-level key in configuration.yaml or package files.\n\nIMPORTANT: Only use when NO UI or API alternative exists. Prefer:\n- Template sensors -> ha_config_set_helper (Template Helper)\n- Automations -> ha_config_set_automation\n- Scripts -> ha_config_set_script\n- Input helpers -> ha_config_set_helper\n- Scenes -> ha_config_set_scene\n\nThis tool is for YAML-only features with no UI/API path (e.g.,\ncommand_line sensors, platform-based MQTT sensors in YAML, rest\nsensors defined in packages).\n\nSafeguards: file backup, YAML validation, top-level key whitelist,\npath traversal blocking, post-edit config check.\n\nIMPORTANT: Check 'post_action' in the response. Most keys require\na full HA restart ('restart_required'). Only template, mqtt, and\ngroup support reload ('reload_available' with 'reload_service').\n\nPreserves YAML comments on sibling keys, file-level comments,\nand Home Assistant tags (!include, !secret, etc.). The 'replace' action\nsubstitutes the subtree as-is, so comments from the old subtree\ndo not carry over.",
2417
+
"title": "Raw YAML Config Edit (Escape Hatch)",
2418
+
"description": "ESCAPE HATCH — raw YAML edit. Use only when NO dedicated tool fits.\n\nThis tool is the WRONG answer for almost everything. Before calling it,\nconfirm that NONE of these apply:\n\n- Template sensors (state-based OR trigger-based) ->\n ha_set_config_entry_helper with domain='template'. The Template\n config-flow helper supports triggers, availability, attributes, device\n class, unit of measurement, and state templates since HA 2024.x. It is\n the correct path even for complex trigger-based sensors. Do NOT edit\n the 'template:' YAML block for this.\n- Automations -> ha_config_set_automation\n- Scripts -> ha_config_set_script\n- Scenes -> ha_config_set_scene\n- Input helpers (input_boolean, input_number, input_text, input_select,\n input_datetime, input_button, counter, timer, schedule) ->\n ha_config_set_helper\n- Groups, min/max, threshold, derivative, statistics, utility_meter\n entities that can be created as helpers -> ha_config_set_helper\n\nThis tool is intended for YAML-only integrations that have no config-flow\nor API equivalent: command_line sensors, REST sensors defined in\npackages, shell_command entries, platform-based notify services, and\nsimilar edge cases. If you are reaching for this to edit 'template:',\n'automation:', 'script:', 'scene:', or 'input_*:', stop and use the\ndedicated tool instead.\n\nA ``justification`` is REQUIRED on every call and is logged for auditing.\nThe justification must explain why no dedicated tool fits. If you cannot\nwrite a concrete justification, you are using the wrong tool.\n\nSafeguards: file backup, YAML validation, top-level key allowlist,\npath traversal blocking, post-edit config check.\n\nCheck 'post_action' in the response. Most keys require a full HA restart\n('restart_required'). Only template, mqtt, and group support reload\n('reload_available' with 'reload_service').\n\nPreserves YAML comments on sibling keys, file-level comments, and Home\nAssistant tags (!include, !secret, etc.). The 'replace' action\nsubstitutes the subtree as-is, so comments from the old subtree do not\ncarry over.",
2419
2419
"inputSchema": {
2420
2420
"properties": {
2421
2421
"yaml_path": {
2422
-
"type": "Annotated[str, Field(description=\"Top-level YAML key to modify(e.g., 'template', 'sensor', 'input_boolean'). Only whitelisted keys are allowed.\")]"
2422
+
"type": "Annotated[str, Field(description=\"Top-level YAML key to modify. Only a narrow allowlist of YAML-only integration keys is accepted (e.g., 'command_line', 'rest', 'shell_command', 'notify', 'utility_meter'). STOP before using this for 'template' — the Template config-flow helper (ha_set_config_entry_helper with domain='template') supports state AND trigger-based template sensors since HA 2024.x and is the correct path. Do NOT use this tool for automations, scripts, scenes, or input_* helpers — they have dedicated tools (ha_config_set_automation, ha_config_set_script, ha_config_set_scene, ha_config_set_helper).\")]"
2423
2423
},
2424
2424
"action": {
2425
2425
"type": "Annotated[str, Field(description=\"Action to perform: 'add' (insert/merge content under key), 'replace' (overwrite key with new content), or 'remove' (delete the key entirely).\")]"
2426
2426
},
2427
+
"justification": {
2428
+
"type": "Annotated[str | None, Field(default=None, description='Required. Explain in one or two sentences why no dedicated tool (ha_set_config_entry_helper for templates, ha_config_set_automation, ha_config_set_script, ha_config_set_scene, ha_config_set_helper) can accomplish this task. Logged for auditing. If you cannot write a concrete justification, you probably want a different tool.')]",
2429
+
"default": null
2430
+
},
2427
2431
"content": {
2428
2432
"type": "Annotated[str | None, Field(default=None, description=\"YAML content for the value under yaml_path. Required for 'add' and 'replace' actions. Must be valid YAML.\")]",
0 commit comments