Four practical patterns for combining Slangify grammars with LLMs.
Convert free text into structured data. This is the core use case.
Prompt instruction:
Convert the following booking request into DSL format.
Output only the DSL line.
Result: the LLM strips noise and maps fields — you parse the DSL.
Ask the LLM to create content that already conforms to your schema.
Example — generate a support-ticket summary in DSL form:
Write a support ticket for a user who cannot log in.
Use this format: customer_name "..." issue_type "..." priority low|medium|high summary "..."
The grammar then validates that the generated text is well-formed before it touches your database.
Convert one structure into another.
Example: turn a raw email into a CRM record.
Given this customer email, produce a CRM record in DSL format:
contact_name "..." company "..." intent "..." follow_up_date YYYY-MM-DD
The LLM handles the semantic mapping; the grammar enforces the output contract.
Use an enum token to constrain the LLM to a fixed vocabulary.
Grammar:
token priority { 'low' | 'medium' | 'high' }
Prompt instruction:
Classify the urgency of this support request as low, medium, or high.
Output only: priority <value>
If the LLM outputs priority urgent, the grammar rejects it. Retry logic or a stricter prompt resolves the mismatch.
| Pattern | When to use |
| Extraction | Unstructured input → known schema |
| Generation | LLM creates content, schema validates it |
| Transformation | Structured input → different structured output |
| Classification | Categorical output from a closed vocabulary |