Yeah guys, I think the very best answer to that is what you have answered: "what kind of invariants" / Dependent Types / Proof Assistants. :) I was afraid of that because those are my answers as well! :)
I asked the question because half part of my intuition says there must be some useful system I am not aware of on the level of logic programming where Prolog sits, but the other half of my intuition accepts that the most sophisticated way might be the Dependent Typed / Proof Assistant way to go on.