Any signal that allows the model to see what's wrong helps.
Checking code is (relatively) easy, you can use static type checks, linters, and execute it to see if it's correct.
Fact checking is harder. A RAG can only check what's in the database, so you have to know what to know beforehand.