# How would you validate macro input?

**URL:** <https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028>\
**Category:** Help\
**Tags:** jinja\
**Created:** [April 7, 2020, 7:39am UTC](https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028 "2020-04-07T07:39:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vish](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/vish/32/371_2.png) [@vish](https://discourse.getdbt.com/u/vish)\
**Post date:** [April 7, 2020, 7:39am UTC](https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028/1 "2020-04-07T07:39:32Z")

</div>

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

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

[actual code.]
{% endmacro %}

```

---

<div class="post-metadata">

**Author:** ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)\
**Post date:** [April 8, 2020, 9:48pm UTC](https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028/2 "2020-04-08T21:48:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vish](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/vish/32/371_2.png) [@vish](https://discourse.getdbt.com/u/vish)\
**Post date:** [April 9, 2020, 6:40am UTC](https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028/3 "2020-04-09T06:40:24Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![terry\_joyce](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/terry_joyce/32/374_2.png) [@terry\_joyce](https://discourse.getdbt.com/u/terry_joyce)\
**Post date:** [April 11, 2020, 5:08pm UTC](https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028/4 "2020-04-11T17:08:43Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [September 13, 2022, 3:54am UTC](https://discourse.getdbt.com/t/how-would-you-validate-macro-input/1028/5 "2022-09-13T03:54:43Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
