Can't seem to eliminate markdown format

I am trying very hard to avoid Markdown format Example In my responses, as I want my response to be HTML only.

“messages”: [
{
“role”: “system”,
“content”: [
{
“type”: “text”,
“text”: “You are a 1-response API. Markdown format is strictly forbidden.”
}
]
},
{
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: “describe briefly the ingredients listed in this pet food one by one, HTML format. You are a 1-response API. Markdown format is strictly forbidden.”
},
{

Every single return contains list formatted as Markdown.

Example:
"The ingredients listed in this pet food are as follows:\n\n1. Whole grain corn - A carbohydrate source that provides energy and dietary fiber.\n2. Poultry by-product meal - A protein source made from grinding clean parts of poultry carcasses.\n3. 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.\n4. Soybean meal - A high-protein soy product that serves as a protein source.\n5. Meat and bone meal - A protein source derived from rendered parts of beef or pork.\n6. Brewers rice - A carbohydrate source that provides energy.\n7. Corn gluten meal - A by-product of corn processing that is high in protein.\n8. Animal digest - A flavor enhancer made from hydrolyzed animal tissues.\n9. Calcium carbonate - A mineral used as a dietary supplement for bone health.\n10. Salt - Used for flavor and as an essential electrolyte.\n11. Choline chloride - A supplement used to support healthy brain and liver function.\n12. Potassium chloride - A source of potassium, important for nerve and muscle function.\n13.

Am I approaching this wrong?
Temperature is set to 0.15.

1 Like

Hi and welcome to the Community!

Instead of even mentioning markdown in both of your system and user message, just ask it to return the output in html.

For example cahnge your system message as follows.

You are a 1-response API. Your output must strictly be provided in html format.

In your user message, you don’t even have to repeat the format instruction and you can just reduce it to

Describe briefly the ingredients listed in this pet food one by one,

See here for the playground example (note: I slightly simplified the user message for the purpose of the example):

1 Like

Thank you so much, ill try it out! My thought with 1-response api was to make sure the response wasn’t ‘conversational’, as in asking follow-up questions etc. I’ll rephrase it or try to leave it out

1 Like

What’s strange is that in playground the problem is non-existing with the same parameters and instructions.

1 Like

Cool - after further thinking about it, I realized this is what it was. I think you can leave it just out.

I want to add that if you would like other adjustments, you can just include that as instruction in the system message. So for instance if you don’t wish the model to bold any of the words, then including a phrase such “Do not bold any words” should do the trick.

1 Like

I’m gonna give it a try via regular API call. Give me a moment.

EDIT

For GPT-4-turbo it returns html with the prompt I shared with you.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pet Food Ingredients</title>
</head>
<body>
<h1>Common Ingredients in Pet Food</h1>
<ul>
<li><strong>Meat and Meat By-products:</strong> These are primary sources of protein. Meat by-products include organs and parts either not desired, or not fit for human consumption.</li>
<li><strong>Poultry and Poultry By-products:</strong> Similar to meat, these ingredients are derived from parts of poultry which are not typically consumed by humans. They are a good source of protein.</li>
<li><strong>Fish:</strong> Provides high-quality protein and is rich in omega-3 fatty acids, which help maintain a pet's skin and coat health.</li>
<li><strong>Grains:</strong> Such as corn, wheat, and rice are common carbohydrates that provide pets with energy. They also contain essential nutrients like fiber, vitamins, and minerals.</li>
<li><strong>Vegetables:</strong> Common vegetables include carrots, peas, and sweet potatoes. They are sources of vitamins, minerals, and fiber.</li>
<li><strong>Fruits:</strong> Apples, blueberries, and cranberries are often used in pet food for their antioxidant properties and vitamins.</li>
<li><strong>Fats:</strong> Usually sourced from oils like chicken fat or fish oil, fats are crucial for energy, cell function, and skin and coat health.</li>
<li><strong>Vitamins and Minerals:</strong> These are added to ensure the pet food meets the nutritional needs of animals. Common additions include vitamin E, vitamin D, calcium, and phosphorus.</li>
<li><strong>Preservatives:</strong> Used to extend the shelf life of pet food. Natural options include tocopherols (vitamin E) or ascorbic acid (vitamin C).</li>
</ul>
</body>
</html>

Same for GPT 3.5 turbo

<ol>
  <li>Proteins: such as chicken, beef, fish, or lamb, provide essential amino acids for muscle growth and maintenance.</li>
  <li>Carbohydrates: like rice, corn, or potatoes, are a source of energy for pets.</li>
  <li>Fats: from sources like chicken fat or fish oil, provide essential fatty acids for a healthy coat and skin.</li>
  <li>Vitamins and minerals: such as vitamin E, vitamin D, and calcium, are essential for overall health and well-being.</li>
  <li>Fiber: from ingredients like beet pulp or oat fiber, aids in digestion and helps maintain a healthy weight.</li>
</ol>

Yes the prompt seems to be working, thanks a bunch for putting in the effort!

2 Likes

As a general rule of thumb: Avoid telling the model what not to do and instead tell it what it should do. It’s ok to include certain instructions that address unwanted behaviour but they should not dominate the prompt - on balance you should frame your instructions positively.

7 Likes

I have the same issue with the chatGPT app (not the API). Even though my custom instructions specifically state “ Please present all mathematical equations and formulas in plain text only, without using LaTeX, markup languages, or any special formatting.”

But when I prompt it to re-write the response without using LaTeX, markup languages, or any special formatting, the new response is just fine.

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:

  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.

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.

3 Likes

There are many reasons why it’s better not to fight the model, but one reason is that every time you use a forbidden phrase, that forbidden phrase will appear repeatedly in system and user messages, resulting in prompts to do what should be forbidden.

Post-processing with scripts is the most reliable method, but I understand the need to make the model follow instructions.

        {
            "role": "system",
            "content": "I want you to respond with HTML tags. Ensure that the entire output conforms to latest HTML format"
        },

I tried using this system message with GPT-3.5-turbo about 20 times.

Although there was one instance of output that did not conform to HTML, there were no cases involving backslashes.
It’s better to avoid including backslashes in user messages.

I hope this advice can be of some help, even if it’s just a little…

Of course, the prompt like this may become invalid in the future.

Hi everyone,

I wanted to do the same thing but i’m working with the crove.app api for building a pdf.
But the text generate by the assistant in the pdf sometimes is at markdown and sometimes not, even though i told him in the function description to return exclusively a text response no markdown.

Can someone have an idea how can i do this ?

It would be very difficult to completely remove markdown from the model’s output.
There is always a possibility that markdown symbols will be output.

In cases like yours where that’s not acceptable, it would be wise to handle it with post-processing as mentioned above.

Another way to get outputs to conform to a specific format without prompting with lots of prohibitions is to employ a few-shot prompt.

Few-shot prompting is when you include several examples of input/output, or even just examples of output as part of your prompt. I usually include an additional message at the end of my instructions with something like:

Examples:
### Prompt: What are the store hours on weekends?
### HTML Response:
<p>Our store hours on weekends are from 9:00 AM to 9:00 PM.</p>

### Prompt: Do you carry gluten-free bread?
### HTML Response:
<p>Yes, we carry a variety of gluten-free breads. Please visit our bakery section.</p>

### Prompt: Can you tell me the price of organic bananas?
### HTML Response:
<p>The price of organic bananas is $0.99 per pound.</p>

### Prompt: Is there a discount on dairy products this week?
### HTML Response:
<p>Yes, we have a 15% discount on all dairy products this week. Visit our dairy section for more details.</p>

### Prompt: Tell me the ingredients in this pet food.
### HTML Response:
<ul>
  <li>Chicken meal</li>
  <li>Brown rice</li>
  <li>Barley</li>
  <li>Oats</li>
  <li>Pea protein</li>
</ul>

and then the model will take that as a queue for how it should answer using HTML. I didn’t write this few-shot prompt, I actually had gpt-4 generate this prompt, asking it to help me write a few-shot prompt for a grocery store helper bot with the example being a question/answer pair involving petfood like you included.

Got it! If you need any specific adjustments or have other preferences, feel free to let me know in the system message. I’m here to help!