Works in Developer tools but not in automation

So the below works fine in the developer tools. but not at all when I try and put it into the automation. it is in the ACTION, it is being read out by a speaker, this is just the part that will not work the rest is fine. No errors it just does not save when I put it in there. Obviously it is written wrong I just have no clue how to make it work and hope someone here can show me. Thanks. Here is code-

    {% set messages_deficit = [
    'Guess you better get a 2nd job to pay the water bill.',
    'Have you considered doing a rain dance?',
    'Looks like it\'s time to invest in a really big umbrella.',
    'Better stock up on bottled water!',
    'Time to start rationing that H2O.',
    'You might need to take a trip to the nearest lake.',
    'Are you sure your rain gauge is working?',
    'Looks like your plants are going to need a little extra love.',
    'Good news - you\'re one step closer to becoming a desert!'
] %}

{% set messages_surplus = [
    'Looks like it\'s time to start building an ark.',
    'Better break out the scuba gear!',
    'Your backyard is turning into a swamp.',
    'Hope you like the sound of rain!',
    'Time to start growing rice in your garden.',
    'Looks like your plants are loving all that water!',
    'Are you sure you don\'t live in a rainforest?',
    'Good news - you\'re one step closer to becoming a mermaid!'
] %}

{% set messages_even = [
    'Perfectly average, just like you!',
    'Boring.',
    'At least you\'re not losing any water.',
    'Not too shabby, not too great.',
    'This calls for a celebration - with water!',
    'Consistent, just like the rain gods intended.',
    'You must be a master gardener.',
    'Average is the new exceptional!'
] %}

{% set lifetime_rainfall = states('sensor.denmans_mountain_lifetime_rain') | float %}
{% set average_rainfall = 37 %}
{% set deficit = average_rainfall - lifetime_rainfall %}

{% if deficit > 0 %}
    There is a rainfall deficit of {{ '%.2f' | format(deficit) }} inches. {{ messages_deficit | random }}
{% elif deficit < 0 %}
    There is a rainfall surplus of {{ '%.2f' | format(-deficit) }} inches. {{ messages_surplus | random }}
{% else %}
    The total rainfall is exactly the average rainfall for a year. {{ messages_even | random }}
{% endif %} 
yaml```

CHAT GPT solved it for me.

{% set lifetime_rainfall = states('sensor.denmans_mountain_lifetime_rain') | float %}
    {% set average_rainfall = 37 %}
    {% set rainfall_difference = average_rainfall - lifetime_rainfall %}

    {% if rainfall_difference > 0 %}
        There is a rainfall deficit of {{ '%.2f' | format(rainfall_difference) }} inches. {{ ['Guess you better get a 2nd job to pay the water bill.',
    'Have you considered doing a rain dance?',
    'Looks like it\'s time to invest in a really big umbrella.',
    'Better stock up on bottled water!',
    'Time to start rationing that H2O.',
    'You might need to take a trip to the nearest lake.',
    'Are you sure your rain gauge is working?',
    'Looks like your plants are going to need a little extra love.',
    'Good news - you\'re one step closer to becoming a desert!'] | random }}
    {% elif rainfall_difference < 0 %}
        There is a rainfall surplus of {{ '%.2f' | format(-rainfall_difference) }} inches. {{ ['Did you ever go to sleep? ',
    'You made of money Bro?. ',
    'Do all of these really need to be on?. '] | random }}
    {% else %}
        The total rainfall is exactly the average rainfall for a year. {{ ['Wow, what a surprise. ',
    'Could you be any more average?',
    'You\'re right on the money, as usual.'] | random }}
    {% endif %}