Dynamically disable models without breaking refs

The problem I’m having

I have 4 models: a, b, c, d

Models a, b, and c create views and model d unions them all at the end

What I would like to do is use a variable array i.e.

vars:
  var_array: ['a', 'b', 'c']

i have each model a, b, and c starting with {% if 'a' in var('var_array') %}

when i use the command dbt compile --vars '{"var_array": "['a, 'c']"}' this compiles completely fine, however if i use the command dbt run --vars '{"var_array": "['a, 'c']"}' model b ends up being included in the target/run dir as an empty query that throws an error

this is what is shown in target/run for model b:

  create view "postgres"."public"."b__dbt_tmp"
    
    
  as (
    
  );

with the corresponding error:

18:37:56    Database Error in model b (models/b.sql)
  syntax error at or near ")"
  LINE 8:   );
            ^

Is there a way to have model b not included in the run depending on what variables are passed through?

Note: I did try to use the if statements to disable the model via the config, but I am using dbt_utils.union_relations in model d to union the outputs of models a, b, and c