I usually tell it very strongly the rules I want it to follow and make sure it writes it to memory. I've also found that when you tell it to use specific components from a library or framework, it does a very decent job.
Extra points if the library/framework has a MCP server or skill available.