For open source llms you can give your grammar to the llm to help it decide what valid next tokens it can generate.