Here is the same advice I give everyone all the time…
Don’t fight the model!
Meet the models where they are. Right now the models are substantially more comfortable with Markdown than they are with HTML. For the foreseeable future there will likely remain some non-zero probability the model response will be formatted with Markdown, so you’ll need to at least check the output before passing it down the chain of your application.
So, instead of wasting time trying to force the model to do something it is reluctant to do and needing to double check its work, just meet the model where it is—lean in, and actually ask it for Markdown, then just post process the Markdown into HTML with pandoc or whatever your preferred Markdown to HTML converter is.
E.g.
If you put the response into a temporary file (in this case resp.md
) and process it to HTML with pandoc,
resp.md:
The ingredients listed in this pet food are as follows:
1. **Whole grain corn** - A carbohydrate source that provides energy and dietary fiber.
2. **Poultry by-product meal** - A protein source made from grinding clean parts of poultry carcasses.
3. **Animal fat preserved with mixed-tocopherols (form of Vitamin E)** - Used as a source of fat, which provides energy and helps in the absorption of fat-soluble vitamins. Mixed-tocopherols are added as a natural preservative.
4. **Soybean meal** - A high-protein soy product that serves as a protein source.
5. **Meat and bone meal** - A protein source derived from rendered parts of beef or pork.
6. **Brewers rice** - A carbohydrate source that provides energy.
7. **Corn gluten meal** - A by-product of corn processing that is high in protein.
8. **Animal digest** - A flavor enhancer made from hydrolyzed animal tissues.
9. **Calcium carbonate** - A mineral used as a dietary supplement for bone health.
10. **Salt** - Used for flavor and as an essential electrolyte.
11. **Choline chloride** - A supplement used to support healthy brain and liver function.
12. **Potassium chloride** - A source of potassium, important for nerve and muscle function.
pandoc -t html 2/resp.md
This is what you get out,
<p>The ingredients listed in this pet food are as follows:</p>
<ol type="1">
<li><strong>Whole grain corn</strong> - A carbohydrate source that
provides energy and dietary fiber.</li>
<li><strong>Poultry by-product meal</strong> - A protein source made
from grinding clean parts of poultry carcasses.</li>
<li><strong>Animal fat preserved with mixed-tocopherols (form of Vitamin
E)</strong> - Used as a source of fat, which provides energy and helps
in the absorption of fat-soluble vitamins. Mixed-tocopherols are added
as a natural preservative.</li>
<li><strong>Soybean meal</strong> - A high-protein soy product that
serves as a protein source.</li>
<li><strong>Meat and bone meal</strong> - A protein source derived from
rendered parts of beef or pork.</li>
<li><strong>Brewers rice</strong> - A carbohydrate source that provides
energy.</li>
<li><strong>Corn gluten meal</strong> - A by-product of corn processing
that is high in protein.</li>
<li><strong>Animal digest</strong> - A flavor enhancer made from
hydrolyzed animal tissues.</li>
<li><strong>Calcium carbonate</strong> - A mineral used as a dietary
supplement for bone health.</li>
<li><strong>Salt</strong> - Used for flavor and as an essential
electrolyte.</li>
<li><strong>Choline chloride</strong> - A supplement used to support
healthy brain and liver function.</li>
<li><strong>Potassium chloride</strong> - A source of potassium,
important for nerve and muscle function.</li>
</ol>
Which renders as,
The ingredients listed in this pet food are as follows:
- Whole grain corn - A carbohydrate source that
provides energy and dietary fiber.
- Poultry by-product meal - A protein source made
from grinding clean parts of poultry carcasses.
- Animal fat preserved with mixed-tocopherols (form of Vitamin
E) - Used as a source of fat, which provides energy and helps
in the absorption of fat-soluble vitamins. Mixed-tocopherols are added
as a natural preservative.
- Soybean meal - A high-protein soy product that
serves as a protein source.
- Meat and bone meal - A protein source derived from
rendered parts of beef or pork.
- Brewers rice - A carbohydrate source that provides
energy.
- Corn gluten meal - A by-product of corn processing
that is high in protein.
- Animal digest - A flavor enhancer made from
hydrolyzed animal tissues.
- Calcium carbonate - A mineral used as a dietary
supplement for bone health.
- Salt - Used for flavor and as an essential
electrolyte.
- Choline chloride - A supplement used to support
healthy brain and liver function.
- Potassium chloride - A source of potassium,
important for nerve and muscle function.
Dont fight the model!
Also, Markdown is a lot more dense than HTML.
The Markdown output in this example is 279-tokens, the HTML output is 367-tokens a savings of about 24\% on your output tokens—plus you don’t need to waste tokens on the instructions telling it to write in HTML.