It’s easy to do at the syntactic level by controlling the sampling. For example, it’s easy and common to restrict output to be valid JSON but just not allowing any tokens that would make it not valid JSON.
But reliably restricting output at the semantic level is very much an open problem.