# Macro to check record count and raise an exception?

**URL:** <https://discourse.getdbt.com/t/macro-to-check-record-count-and-raise-an-exception/3029>\
**Category:** Archive\
**Created:** [September 10, 2021, 6:28pm UTC](https://discourse.getdbt.com/t/macro-to-check-record-count-and-raise-an-exception/3029 "2021-09-10T18:28:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gayathri](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gayathri](https://discourse.getdbt.com/u/gayathri)\
**Post date:** [September 10, 2021, 6:28pm UTC](https://discourse.getdbt.com/t/macro-to-check-record-count-and-raise-an-exception/3029/1 "2021-09-10T18:28:30Z")

</div>

Hello all,

dbt newbie here looking for help 🙂

I would like to call a macro as a post hook after the model is built. This should check the count of records by a specific column and raise an error according to variable set.

Any ideas on how to go about this please? Thanks.

---

<div class="post-metadata">

**Author:** ![gayathri](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@gayathri](https://discourse.getdbt.com/u/gayathri)\
**Post date:** [September 10, 2021, 8:57pm UTC](https://discourse.getdbt.com/t/macro-to-check-record-count-and-raise-an-exception/3029/2 "2021-09-10T20:57:19Z")

</div>

Combing through more documentation, I stumbled across the [execute](https://docs.getdbt.com/reference/dbt-jinja-functions/execute) Jinja variable - perhaps this might help? Although I am now curious what would the model in this example (models/order\_payment\_methods.sql) return?

I know a normal select is wrapped around a CREATE TABLE statement whilst building a model. Does this sql create a table of distinct payment\_method?
