Convert string in YAML "variable" to jinja variable with the name in the string?

Hello,

I have a lot of scripts that take in some number of parameters. I am trying to standardize the sprawl of ad-hoc checking (which is missing in many places still) where I make sure that the calling script or automation passed in the variable, so I don’t create more difficult-to-detect bugs down the line.

What I’d really like is to be able, in the variables: section of a script, to have a simple list of variables. And then a reusable template that can be called first thing.

For example,

variables:
  required_inputs:
    - entity_id
    - brightness

In a Jinja template, I know that the variable required_inputs will be available as a list of strings. But I haven’t found a way–and perhaps there isn’t one; I can think of good reasons why this might be a dangerous feature in some cases–to use that list of strings to get at variable names in Jinja based on the contents of those strings, the way that I would be able to, say, with dictionary keys.

What I’d really like is to be able to check whether each string corresponds to a variable name available via Jinja to use, for example, the defined test, and maybe output a debug statement with a list of variables that were not defined.

In the above example, the template I’d like would in its simplest form do the equivalent of

entity_id is defined and brightness is defined

and take some appropriate action if the test fails.