# Compilation Error when using a jinja loop and source

**URL:** <https://discourse.getdbt.com/t/compilation-error-when-using-a-jinja-loop-and-source/18876>\
**Category:** Help\
**Tags:** dbt-core, jinja\
**Created:** [March 31, 2025, 5:32pm UTC](https://discourse.getdbt.com/t/compilation-error-when-using-a-jinja-loop-and-source/18876 "2025-03-31T17:32:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nleatham](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nleatham](https://discourse.getdbt.com/u/nleatham)\
**Post date:** [March 31, 2025, 5:32pm UTC](https://discourse.getdbt.com/t/compilation-error-when-using-a-jinja-loop-and-source/18876/1 "2025-03-31T17:32:26Z")

</div>

## The problem I’m having

I wrote a jinja loop to simplify a script:  
{% set table\_dict = {  
“test”: {“report”: “Report”, “data\_lag”: “No Lag”, “source”: “\_test”},  
}%}

{% for table\_name, value in table\_dict.items() %}  
\_{{ table\_name }} as (  
select  
‘{{ table\_name }}’ as data\_src,  
‘{{ value[“report”] }}’ as report,  
‘{{ value[“data\_lag”] }}’ as data\_lag,  
{{ filename\_date(‘“filename”’) }} as current\_refresh,  
{{ filename\_date(‘“filename”’) }} as pull\_dt,  
‘Monthly’ as updated

```
from {{ source('ops', '{{ value["source"] }}') }} limit 1
),

```

{% endfor %}

It errors out with a compilation error:  
16:56:37 Running with dbt=1.7.13  
16:56:37 Registered adapter: duckdb=1.7.4  
16:56:37 Encountered an error:  
Compilation Error  
Model ‘’ (models\reports) depends on a source named ‘ops.{{ values.get(source) }}’ which was not found

It seems that dbt compiles source first and promptly errors out. I’ve verified that everything compiles correctly when not trying to insert the string into source. Is this something I can fix? It would be really helpful.

---

<div class="post-metadata">

**Author:** ![tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/tyler/32/4230_2.png) [@tyler](https://discourse.getdbt.com/u/tyler)\
**Post date:** [April 2, 2025, 3:06am UTC](https://discourse.getdbt.com/t/compilation-error-when-using-a-jinja-loop-and-source/18876/2 "2025-04-02T03:06:25Z")

</div>

Hey! I think you’ve got a nesting issue, see: [Don't nest your curlies | dbt Developer Hub](https://docs.getdbt.com/best-practices/dont-nest-your-curlies)
