# How can I get compiled model sql from tests

**URL:** https://discourse.getdbt.com/t/how-can-i-get-compiled-model-sql-from-tests/13408
**Category:** Help
**Tags:** testing
**Created:** [May 17, 2024, 4:05am UTC](https://discourse.getdbt.com/t/how-can-i-get-compiled-model-sql-from-tests/13408 "2024-05-17T04:05:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@frank](https://discourse.getdbt.com/u/frank)
#### Post date: [May 17, 2024, 4:05am UTC](https://discourse.getdbt.com/t/how-can-i-get-compiled-model-sql-from-tests/13408/1 "2024-05-17T04:05:51Z")

</div>

## The problem I’m having

I am creating customer tests and which will run in Anomalo.

```auto
{% test my_test(model, column_name) %}

    {%- set model_node = graph.nodes.get("model.common_resources.my_graph_source_key") -%}
    {%- set raw_code = model_node["raw_code"] -%}
    {%- set compiled_code = model_node["compiled_code"] -%}

    with cte AS (
        {{compiled_code}}
    )
    SELECT * FROM cte
    WHERE ...
 
{% endtest %}

```

I can get `model_node`, `raw_code`, but I cannot get `compiled_code` while run dbt compile.

May I ask how can I get the compiled sql from models in dbt tests?

## The context of why I’m trying to do this

We want to have a unified test for platform without considering about the product sql query.
