How would you validate macro input?

example (prevent users from calling a macro with FALSE instead of False ):

{% macro temp(bool1=False) %}
{% if bool1 not in [True, False] %} 
BLA BLA BREAK THE SQL
{% endif %}

[actual code.]
{% endmacro %}

@vish I think you should be able to use jinja exceptions here: https://docs.getdbt.com/docs/writing-code-in-dbt/jinja-context/exceptions/

2 Likes

thanks,
is there any way to code a schema test to expect an error ?
i.e. I want to pass a wrong value, and the tests should expect a failure ?

@vish Keep in mind the schema tests run against the database after your data is built, but you’re hoping to catch a coding exception at compile-time when the macro is used to build the SQL. I think @joellabes has the right approach: have the macro test its input and throw an exception if there’s an out-of-bounds value.

2 Likes