# Prompting strategy
URL: https://docs.datarobot.com/en/docs/reference/gen-ai-ref/prompting-reference.html

> Learn techniques for creating prompts that optimize chat results.

# Prompting strategy

The following sections provide both basic and advanced [few shot prompting](https://docs.datarobot.com/en/docs/reference/gen-ai-ref/prompting-reference.html#few-shot-prompting) guidance.

## Best practices for prompt engineering

Prompt engineering refers to the process of carefully crafting the input prompts that you give to an LLM to maximize the usefulness of the output it generates. This is a critical step in getting the most out of these models, as the way you phrase your prompt can significantly influence the response. The following are some best practices for prompt engineering:

| Characteristic | Explanation |
| --- | --- |
| Specificity | Make prompts as specific as possible. Instead of asking “What’s the weather like?”, ask “What’s the current temperature in San Francisco, California?”. The latter is more likely to yield the information you’re looking for. |
| Explicit instructions | If you have a specific format or type of answer in mind, make that clear in your prompt. For example, if you want a list, ask for a list. If you want a yes or no answer, ask for that. |
| Contextual information | If relevant, provide some context to guide the model. For instance, if you’re asking for advice on writing a scientific type of content, make sure to mention that in your prompt. |
| Use of examples | When you want the model to generate in a particular style or format, giving an example can help guide the output. For instance, if you want a rhyming couplet, you could include an example of one in your prompt. |
| Prompt length | While it can be useful to provide context, remember that longer prompts may lead the model to focus more on the later parts of the prompt and disregard earlier information. Be concise and to the point. |
| Bias and ethical considerations | Be aware that the way you phrase your prompt can influence the output in terms of bias and harmful response. Ensure your prompts are as neutral and fair as possible, and be aware that the model can reflect biases present in its training data. |
| Temperature and Top P Settings | In addition to the prompt itself, you can also adjust the ‘temperature’ and ‘Top P’ settings. Higher temperature values make output more random, while lower values make it more deterministic. Top P controls the diversity of the output by limiting the model to consider only a certain percentile of most likely next words. |
| Token limitations | Be aware of the maximum token limitations of the model. For example, GPT-3.5 Turbo has a maximum limit of 4096 tokens. If your prompt is too long, it could limit the length of the model’s response. |

These are some of the key considerations in prompt engineering, but the exact approach depends on the specific use case, model, and kind of output you’re looking for. It’s often a process of trial and error and can require a good understanding of both your problem domain and the capabilities and limitations of the model.

## Effective prompting strategies

This section uses the following example to identify elements of prompt engineering:

You are a world-renowned poet in the early 1800s. Write a poem in the style of Edgar Allan Poe. It must be 10 sentences long and use “set up, rhyme” format.

Consider the elements through the following images.

#### Persona

Persona provides a role or voice to ensure that answers resemble a specific counterpart throughout (e.g., profession, known person).

#### Context and sensitivity

Context is information or nuance that can steer the model toward a given setting (e.g., temporal, subject matter). Specificity provides additional details as part of the context that can lead to better results (e.g., tone and style).

#### Instruction

Instruction is a specific task you want the model to perform (e.g., write, translate, summarize).

#### Rules

Rules provide specifications to limit or otherwise restrain the response (e.g., word limit, topics to avoid).

#### Output format

The output format is the type and/or format of the output. Optionally, you can provide examples
(e.g., question/answer, headline) to further refine the desired response.

#### Example response

## Few-shot prompting

Few-shot prompting is a technique for generating or classifying text based on a limited number of examples or prompts—"in-context learning." The examples, or "shots," condition a model to follow patterns in the provided context; it can then generate coherent and contextually relevant text even if it has never seen similar examples during training. This is in contrast to traditional machine learning, where models typically require a large amount of labeled training data. Few-shot prompting makes the model a good candidate for tasks like text generation, text summarization, translation, question-answering, and sentiment analysis without requiring fine-tuning on a specific dataset.

A simple example of few-shot prompting is used in categorizing customer feedback as positive or negative. By showing the model three examples of positive and negative feedback, when the model sees unclassified feedback it can assign a rating based on the first three examples. Few-shot prompting is when you show the model 2 or more examples; zero-shot and one-shot prompting are similar techniques.

The following shows the use of few-shot prompting in DataRobot. In the system prompt field, provide a prompt and some examples for learning:

```
```
Given text in a customer support ticket text, determine the name of the product it refers to, as well as the issue type. The issue type can be "hardware" or "software". Format the response as JSON with two keys, "product" and "issue type".

---------------
Examples:

Input: I'm encountering a bug in TPS Report Generator Enterprise Edition. Whenever I click "Generate", the application crashes. Are there any updates or fixes available?
Output: {"product": "TPS Report Generator Enterprise Edition", "issue_type": "software"}

Input: The screen is flickering on my Acme Phone 5+, and I'm unable to use it. What should I do? I want to install a few games and performed a factory reset, hoping it would resolve the problem, but it didn't help.
Output: {"product": "Acme Phone 5+", "issue_type": "hardware"}
---------------
```
```

After providing the LLM with that context, try some example prompts:

Prompt: I've noticed a peculiar error message popping up on my PrintPro 9000 screen. It says "PC LOAD LETTER". What does it mean?

Prompt: I cannot install firmware v12.1 on my Print Pro 9002. It says "Incompatible product version".

See the [MIT Prompt Engineering Guide](https://www.promptingguide.ai/techniques/fewshot) for more detailed information.

---
