When you are coding, ask the AI to write the test before it writes the function.
Use this prompt:
Before you write the code, write three tests that prove it works: one normal case, one empty case, one broken case.
It may sound backwards. It isn't.
It forces the AI to define what 'working' actually means before it starts improvising.