Skip to content

Add TARGET_FIELDS to config validation#150238

Merged
abmantis merged 3 commits into
home-assistant:devfrom
arturpragacz:h/config-validation/add-target-fields
Aug 26, 2025
Merged

Add TARGET_FIELDS to config validation#150238
abmantis merged 3 commits into
home-assistant:devfrom
arturpragacz:h/config-validation/add-target-fields

Conversation

@arturpragacz
Copy link
Copy Markdown
Member

@arturpragacz arturpragacz commented Aug 7, 2025

Proposed change

New streamlined TARGET_FIELDS was added for use in LLM fields serializer.

TARGET_SERVICE_FIELDS, that was used before, includes a lot of bloat, that accumulated over the years. That schema accepts things like:

  • non-string entity ids
  • upper- and mixed-case entity ids
  • entity entry ids in addition to entity ids
  • templates
  • literal strings "all" or "none" and their variants differing in case

None of that should be present in the validation schema for the LLMs, as we want them to always give us the right output, and don't need to be involved with all that accumulated baggage.

The new schema should also be used for the new targeted conditions and triggers, as we don't have to concern ourselves with backwards compatibility there, and should be stricter in the input we accept.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings August 7, 2025 22:54
@arturpragacz arturpragacz requested a review from a team as a code owner August 7, 2025 22:54
@home-assistant home-assistant Bot added cla-signed code-quality core small-pr PRs with less than 30 lines. labels Aug 7, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new TARGET_FIELDS constant for use in LLM field serialization, replacing the previous use of TARGET_SERVICE_FIELDS. The change streamlines target field validation by simplifying the schema structure to only accept arrays of strings for each target type (entity_id, device_id, area_id, floor_id, label_id).

Key changes:

  • Adds a new TARGET_FIELDS validation schema with simplified array-only structure
  • Updates the LLM selector serializer to use the new TARGET_FIELDS instead of TARGET_SERVICE_FIELDS
  • Updates corresponding tests to reflect the simplified schema structure

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
homeassistant/helpers/config_validation.py Adds new TARGET_FIELDS constant with simplified array-based validation for target fields
homeassistant/helpers/llm.py Updates selector serializer to use new TARGET_FIELDS instead of TARGET_SERVICE_FIELDS
tests/helpers/test_llm.py Updates test expectations to match the simplified target selector schema output

Comment thread homeassistant/helpers/config_validation.py
@arturpragacz arturpragacz force-pushed the h/config-validation/add-target-fields branch from 9d30e3e to 702828e Compare August 7, 2025 23:32
@MartinHjelmare
Copy link
Copy Markdown
Member

MartinHjelmare commented Aug 20, 2025

Please explain in the PR description why it's good to use the new validator instead of TARGET_SERVICE_FIELDS, in the llm helper.

@MartinHjelmare MartinHjelmare marked this pull request as draft August 20, 2025 10:20
@arturpragacz arturpragacz marked this pull request as ready for review August 21, 2025 12:58
@arturpragacz
Copy link
Copy Markdown
Member Author

@MartinHjelmare Done.

Copy link
Copy Markdown
Member

@abmantis abmantis left a comment

Choose a reason for hiding this comment

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

Thanks @arturpragacz !

@abmantis abmantis merged commit d5c2086 into home-assistant:dev Aug 26, 2025
48 checks passed
@arturpragacz arturpragacz deleted the h/config-validation/add-target-fields branch August 26, 2025 18:51
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants