# Prompt Lab #

In the Prompt Lab in IBM watsonx\.ai, you can experiment with prompting different foundation models, explore sample prompts, and save and share your best prompts\.

You use the Prompt Lab to engineer effective prompts that you submit to deployed foundation models for inferencing\. You do not use the Prompt Lab to create new foundation models\.

This video provides a visual method to learn the concepts and tasks in this documentation\.

## Requirements ##

If you signed up for watsonx\.ai and you have a sandbox project, all requirements are met and you're ready to use the Prompt Lab\.

You must meet these requirements to use the Prompt Lab:

<!-- <ul> -->

 *  You must have a project\.
 *  You must have the **Editor** or **Admin** role in the project\.
 *  The project must have an associated Watson Machine Learning service instance\. Otherwise, you are prompted to associate the service when you open the Prompt Lab\.

<!-- </ul> -->

## Creating and running a prompt ##

To create and run a new prompt, complete the following steps:

<!-- <ol> -->

1.  From the [watsonx\.ai home page](https://dataplatform.cloud.ibm.com/wx/home?context=wx), choose a project, and then click **Experiment with foundation models and build prompts**\.

<!-- </ol> -->

<!-- <ol> -->

1.  Select a model\.
2.  Enter a prompt\.
3.  If necessary, update model parameters or add prompt variables\.
4.  Click **Generate**\.
5.  To preserve your work, so you can reuse or share a prompt with collaborators in the current project, save your work as a project asset\. For more information, see [Saving prompts](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-save.html)\.

<!-- </ol> -->

To run a sample prompt, complete the following steps:

<!-- <ol> -->

1.  From the *Sample prompts* menu in the Prompt Lab, select a sample prompt\.
    
    The prompt is opened in the editor and an appropriate model is selected.
2.  Click **Generate**\.

<!-- </ol> -->

## Prompt editing options ##

You type your prompt in the prompt editor\. The prompt editor has the following modes:

**Freeform** : You add your prompt in plain text\. Your prompt text is sent to the model exactly as you typed it\. : Quotation marks in your text are escaped with a backslash (`\"`)\. Newline characters are represented by `\n`\. Apostrophes are escaped (`it'\''s`) so that they can be handled properly in the cURL command\.

**Structured** : You add parts of your prompt into the appropriate fields: : \- **Instruction**: Add an instruction if it makes sense for your use case\. An instruction is an imperative statement, such as *Summarize the following article*\. : \- **Examples**: Add one or more pairs of examples that contain the input and the corresponding output that you want\. Providing a few example input\-and\-output pairs in your prompt is called *few\-shot prompting*\. If you need a specific prefix to the input or the output, you can replace the default labels, "Input:" or "Output:", with the labels you want to use\. A space is added between the example label and the example text\. : \- **Test your input**: In the *Try* area, enter the final input of your prompt\. : Structured mode is designed to help new users create effective prompts\. Text from the fields is sent to the model in a template format\.

## Model and prompt configuration options ##

You must specify which model to prompt and can optionally set parameters that control the generated result\.

### Model choices ###

In the Prompt Lab, you can submit your prompt to any of the models that are supported by watsonx\.ai\. You can choose recently\-used models from the drop\-down list\. Or you can click **View all foundation models** to view all the supported models, filter them by task, and read high\-level information about the models\.

If you tuned a foundation model by using the Tuning Studio and deployed the tuned model, your tuned model is also available for prompting from the Prompt Lab\.

### Model parameters ###

To control how the model generates output in response to your prompt, you can specify decoding parameters and stopping criteria\. For more information, see [Model parameters for prompting](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-model-parameters.html)\.

### Prompt variables ###

To add flexibility to your prompts, you can define prompt variables\. A prompt variable is a placeholder keyword that you include in the static text of your prompt at creation time and replace with text dynamically at run time\. For more information, see [Building reusable prompts](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-variables.html)\.

### AI guardrails ###

When you set the **AI guardrails** switcher to **On**, harmful language is automatically removed from the input prompt text and from the output that is generated by the model\. Specifically, any sentence in the input or output that contains harmful language is replaced with a message that says that potentially harmful text was removed\.

## Prompt code ##

If you want to run the prompt programmatically, you can view and copy the prompt code or use the Python library\.

### View code ###

When you click the **View code** icon (![</>](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/code.svg)), a cURL command is displayed that you can call from outside the Prompt Lab to submit the current prompt and parameters to the selected model and get a generated response\.

In the command, there is a placeholder for an IBM Cloud IAM token\. For information about generating the access token, see [Generating an IBM Cloud IAM token](https://cloud.ibm.com/docs/account?topic=account-iamtoken_from_apikey)\.

### Programmatic alternative to the Prompt Lab ###

The Prompt Lab graphical interface is a great place to experiment and iterate with your prompts\. However, you can also prompt foundation models in watsonx\.ai programmatically by using the Python library\. For details, see [Foundation models Python library](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-python-lib.html)\.

## Available prompts ##

In the side panel, you can access sample prompts, your session history, and saved prompts\.

### Samples ###

A collection of sample prompts are available in the Prompt Lab\. The samples demonstrate effective prompt text and model parameters for different tasks, including classification, extraction, content generation, question answering, and summarization\.

When you click a sample, the prompt text loads in the editor, an appropriate model is selected, and optimal parameters are configured automatically\.

### History ###

As you experiment with different prompt text, model choices, and parameters, the details are captured in the session history each time you submit your prompt\. To load a previous prompt, click the entry in the history and then click **Restore**\.

### Saved ###

From the *Saved prompt templates* menu, you can load any prompts that you saved to the current project as a prompt template asset\.

## Learn more ##

<!-- <ul> -->

 *  [Security and privacy for foundation models](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-security.html)
 *  [Building reusable prompts](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-variables.html)
 *  [Saving prompts](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-save.html)
 *  [Model parameters for prompting](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-model-parameters.html)
 *  [Sample prompts](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html)
 *  [Prompt tips](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-tips.html)
 *  Try these tutorials:
    
    <!-- <ul> -->
    
     *  [Prompt a foundation model using Prompt Lab](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-prompt-lab.html)
     *  [Prompt a foundation model with the retrieval-augmented generation pattern](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/get-started-fm-notebook.html)
    
    <!-- </ul> -->
    
<!-- </ul> -->

<!-- <ul> -->

 *  Watch these other prompt lab videos

<!-- </ul> -->

**Parent topic:**[Foundation models](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-overview.html)

<!-- </article "role="article" "> -->