What is Prompt Engineering?

When working with an LLM to gain knowledge, it is important to craft the prompts in such a way to get the best and most accurate results possible. Large Language Models (LLMs) are very precise/logical in their results, so careful creation of the prompts will result in better responses:

📘

The process of creating accurate LLM requests is known as prompt engineering.

Chat roles play a large part in creating good prompts.

Example: "Who won the AL batting title in 2004?"

The default response in Corcel is:

In 2004, the American League (AL) batting title was won by Ichiro Suzuki of the Seattle Mariners. He finished the season with a batting average of .372.

This is an accurate response, but perhaps it is too verbose. How can we make the response just as accurate, but shorter?

Let's change the system prompt:

 [
    {
      "role": "system",
      "content": "You are a helpful baseball statistics assistant.  Provide brief answers only. "
    },
    {
      "role": "user",
      "content": "Who won the AL batting title in 2004?"
    }
  ]

Ichiro Suzuki won the AL batting title in 2004.

Much better, but can we improve?

 [
    {
      "role": "system",
      "content": "You are a helpful baseball statistics assistant.   Provide the minimum length response possible."
    },
    {
      "role": "user",
      "content": "Who won the AL batting title in 2004?"
    }
  ]

"Ichiro Suzuki."

We can try different years, and we always get just the name of the baseball player who won the AL batting title.

Modification of the result

What if we wanted the team name, and the batting average that awarded the player batting champion? Let's request a CSV response from the model:

 {
            "role": "system",
            "content": "You are a helpful baseball statistics assistant.   Provide only CSV with names, years, teams and the data requested."
        },
        {
            "role": "user",
            "content": "who won the AL batting title in 2004?"
        }

The result is formatted as a CSV.

Name,Year,Team,Batting Average
Ichiro Suzuki,2004,Seattle Mariners,.372

Note: This also took some wrangling with the prompt "Provide a CSV with" added lots of sentences around the CSV. "Provide only CSV" - and the result is just the CSV.