I’m not sure it would work in this context, but have you considered using Ecto’s fragment/1?
fragment/1