# Prompting
URL: https://docs.datarobot.com/en/docs/api/reference/sdk/gen-prompting.html

# Prompting

### class datarobot.models.genai.chat.Chat

Metadata for a DataRobot GenAI chat.

- Variables:

#### classmethod create(name, llm_blueprint)

Creates a new chat.

- Parameters:
- Returns: chat – The created chat.
- Return type: Chat

#### classmethod get(chat)

Retrieve a single chat.

- Parameters: chat ( Chat or str ) – The chat you want to retrieve. Accepts chat or chat ID.
- Returns: chat – The requested chat.
- Return type: Chat

#### classmethod list(llm_blueprint=None, sort=None)

List all chats available to the user. If the LLM blueprint is specified,
results are restricted to only those chats associated with the LLM blueprint.

- Parameters:
- Returns: chats – Returns a list of chats.
- Return type: list[Chat]

#### delete()

Delete the single chat.

- Return type: None

#### update(name)

Update the chat.

- Parameters: name ( str ) – The new name for the chat.
- Returns: chat – The updated chat.
- Return type: Chat

### class datarobot.models.genai.chat_prompt.ChatPrompt

Metadata for a DataRobot GenAI chat prompt.

- Variables:

#### classmethod create(text, llm_blueprint=None, chat=None, llm=None, llm_settings=None, vector_database=None, vector_database_settings=None, wait_for_completion=False, metadata_filter=None)

Create a new ChatPrompt. This submits the prompt text to the LLM. Either llm_blueprint
or chat is required.

- Parameters:

#### update(custom_metrics=None, feedback_metadata=None)

Update the chat prompt.

- Parameters:
- Returns: chat_prompt – The updated chat prompt.
- Return type: ChatPrompt

#### classmethod get(chat_prompt)

Retrieve a single chat prompt.

- Parameters: chat_prompt ( ChatPrompt or str ) – The chat prompt you want to retrieve, either ChatPrompt or chat prompt ID.
- Returns: chat_prompt – The requested chat prompt.
- Return type: ChatPrompt

#### classmethod list(llm_blueprint=None, playground=None, chat=None)

List all chat prompts available to the user. If the llm_blueprint, playground, or chat
is specified then the results are restricted to the chat prompts associated with that
entity.

- Parameters:
- Returns: chat_prompts – A list of chat prompts available to the user.
- Return type: list[ChatPrompt]

#### delete()

Delete the single chat prompt.

- Return type: None

#### create_llm_blueprint(name, description='')

Create a new LLM blueprint from an existing chat prompt.

- Parameters:
- Returns: llm_blueprint – The created LLM blueprint.
- Return type: LLMBlueprint

### class datarobot.models.genai.comparison_chat.ComparisonChat

Metadata for a DataRobot GenAI comparison chat.

- Variables:

#### classmethod create(name, playground)

Creates a new comparison chat.

- Parameters:
- Returns: comparison_chat – The created comparison chat.
- Return type: ComparisonChat

#### classmethod get(comparison_chat)

Retrieve a single comparison chat.

- Parameters: comparison_chat ( ComparisonChat or str ) – The comparison chat you want to retrieve. Accepts ComparisonChat or
  comparison chat ID.
- Returns: comparison_chat – The requested comparison chat.
- Return type: ComparisonChat

#### classmethod list(playground=None, sort=None)

List all comparison chats available to the user. If the playground is specified,
results are restricted to only those comparison chats associated with the playground.

- Parameters:
- Returns: comparison_chats – Returns a list of comparison chats.
- Return type: list[ComparisonChat]

#### delete()

Delete the single comparison chat.

- Return type: None

#### update(name)

Update the comparison chat.

- Parameters: name ( str ) – The new name for the comparison chat.
- Returns: comparison_chat – The updated comparison chat.
- Return type: ComparisonChat

### class datarobot.models.genai.comparison_prompt.ComparisonPrompt

Metadata for a DataRobot GenAI comparison prompt.

- Variables:

#### update(additional_llm_blueprints=None, wait_for_completion=False, feedback_result=None, **kwargs)

Update the comparison prompt.

- Parameters: additional_llm_blueprints ( list[LLMBlueprint or str] ) – The additional LLM blueprints you want to submit the comparison prompt.
- Returns: comparison_prompt – The updated comparison prompt.
- Return type: ComparisonPrompt

#### classmethod create(llm_blueprints, text, comparison_chat=None, wait_for_completion=False, metadata_filter=None)

Create a new ComparisonPrompt. This submits the prompt text to the LLM blueprints that
are specified.

- Parameters:

#### classmethod get(comparison_prompt)

Retrieve a single comparison prompt.

- Parameters: comparison_prompt ( str ) – The comparison prompt you want to retrieve. Accepts entity or ID.
- Returns: comparison_prompt – The requested comparison prompt.
- Return type: ComparisonPrompt

#### classmethod list(llm_blueprints=None, comparison_chat=None)

List all comparison prompts available to the user that include the specified LLM blueprints
or from the specified comparison chat.

- Parameters:
- Returns: comparison_prompts – A list of comparison prompts available to the user that use the specified LLM
  blueprints.
- Return type: list[ComparisonPrompt]

#### delete()

Delete the single comparison prompt.

- Return type: None

### class datarobot.models.genai.playground.Playground

Metadata for a DataRobot GenAI playground.

- Variables:

#### classmethod create(name, description='', use_case=None, copy_insights=None, playground_type=PlaygroundType.RAG)

Create a new playground.

- Parameters:
- Returns: playground – The created playground.
- Return type: Playground

#### classmethod get(playground_id)

Retrieve a single playground.

- Parameters: playground_id ( str ) – The ID of the playground you want to retrieve.
- Returns: playground – The requested playground.
- Return type: Playground

#### classmethod list(use_case=None, search=None, sort=None)

List all playgrounds available to the user. If the use_case is specified or can be
inferred from the Context then the results are restricted to the playgrounds
associated with the UseCase.

- Parameters:
- Returns: playgrounds – A list of playgrounds available to the user.
- Return type: list[Playground]

#### update(name=None, description=None)

Update the playground.

- Parameters:
- Returns: playground – The updated playground.
- Return type: Playground

#### delete()

Delete the playground.

- Return type: None

### class datarobot.enums.PromptType

Supported LLM blueprint prompting types.

### class datarobot.models.genai.user_limits.UserLimits

Counts for user limits for LLM APIs and vector databases.

#### classmethod get_vector_database_count()

Get the count of vector databases for the user.

- Return type: APIObject

#### classmethod get_llm_requests_count()

Get the count of LLMs requests made by the user.

- Return type: APIObject

### class datarobot.models.genai.chat_prompt.ResultMetadata

Metadata for the result of a chat prompt submission.

- Variables:

### class datarobot.models.genai.prompt_trace.PromptTrace

Prompt trace contains aggregated information about a prompt execution.

- Variables:

#### classmethod list(playground)

List all prompt traces for a playground.

- Parameters: playground ( str ) – The ID of the playground to list prompt traces for.
- Returns: prompt_traces – List of prompt traces for the playground.
- Return type: list[PromptTrace]

#### classmethod export_to_ai_catalog(playground)

Export prompt traces to AI Catalog as a CSV.

- Parameters: playground ( str ) – The ID of the playground to export prompt traces for.
- Returns: status_url – The URL where the status of the job can be monitored
- Return type: str

### class datarobot.models.genai.prompt_trace.TraceMetadata

Trace metadata contains information about all the users and chats that are relevant to
this playground.

- Variables: users ( list[dict] ) – The users who submitted the prompt.

#### classmethod get(playground)

Get trace metadata for a playground.

- Parameters: playground ( str ) – The ID of the playground to get trace metadata for.
- Returns: trace_metadata – The trace metadata for the playground.
- Return type: TraceMetadata

### class datarobot.models.genai.prompt_template.PromptTemplate

A prompt template that can have multiple versions.

- Variables:

#### classmethod create(name, description='')

Create a new prompt template.

- Parameters:
- Returns: The created prompt template.
- Return type: PromptTemplate
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> template = dr.genai.PromptTemplate.create(
> ...     name="Customer Support",
> ...     description="Template for support responses"
> ... )
> ```

#### classmethod list(sort=None, search=None)

List all prompt templates available to the user.

- Parameters:
- Returns: A list of prompt templates.
- Return type: List[PromptTemplate]
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> templates = dr.genai.PromptTemplate.list(sort="-creationDate")
> ```

#### classmethod get(prompt_template_id)

Get a prompt template by ID.

- Parameters: prompt_template_id ( str ) – The ID of the prompt template to retrieve.
- Returns: The requested prompt template.
- Return type: PromptTemplate
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> template = dr.genai.PromptTemplate.get("507f1f77bcf86cd799439011")
> ```

#### create_version(prompt_text, variables=None, commit_comment='')

Create a new version of this prompt template.

- Parameters:
- Returns: The created version.
- Return type: PromptTemplateVersion
- Raises:

> [!NOTE] Examples
> ```
> >>> from datarobot.models.genai.prompt_template import Variable
> >>> template.create_version(
> ...     prompt_text="Hello {{ name }}, regarding {{ issue }}",
> ...     variables=[
> ...         Variable(name="name", type="str", description="Customer name"),
> ...         Variable(name="issue", type="str", description="Issue type")
> ...     ],
> ...     commit_comment="Initial version"
> ... )
> ```

#### list_versions()

List all versions of this prompt template.

- Returns: A list of versions for this template.
- Return type: List[PromptTemplateVersion]
- Raises:

> [!NOTE] Examples
> ```
> >>> versions = template.list_versions()
> ```

#### get_version(prompt_template_version_id)

Get a specific version of this prompt template.

- Parameters: prompt_template_version_id ( str ) – The ID of the version to retrieve.
- Returns: The requested version.
- Return type: PromptTemplateVersion
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> template = dr.genai.PromptTemplate.get("507f1f77bcf86cd799439011")
> >>> version = template.get_version("507f1f77bcf86cd799439012")
> ```

#### get_latest_version()

Get the latest version of this prompt template.

- Returns: The latest version, or None if no versions exist.
- Return type: Optional[PromptTemplateVersion]
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> template = dr.genai.PromptTemplate.get("507f1f77bcf86cd799439011")
> >>> latest = template.get_latest_version()
> >>> if latest:
> ...     print(f"Version {latest.version}")
> ```

### class datarobot.models.genai.prompt_template.PromptTemplateVersion

A specific version of a prompt template.

- Variables:

#### classmethod get(prompt_template_id, prompt_template_version_id)

Get a specific prompt template version by ID.

- Parameters:
- Returns: The requested prompt template version.
- Return type: PromptTemplateVersion
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> version = dr.genai.PromptTemplateVersion.get("prompt_template_id", "prompt_template_version_id")
> ```

#### classmethod create(prompt_template_id, prompt_text, variables=None, commit_comment='')

Create a new version of a prompt template.

- Parameters:
- Returns: The created version.
- Return type: PromptTemplateVersion
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> from datarobot.models.genai.prompt_template import Variable
> >>> version = dr.genai.PromptTemplateVersion.create(
> ...     prompt_template_id="507f1f77bcf86cd799439011",
> ...     prompt_text="Hello {{ name }}, regarding {{ issue }}",
> ...     variables=[
> ...         Variable(name="name", type="str", description="Customer name"),
> ...         Variable(name="issue", type="str", description="Issue type")
> ...     ],
> ...     commit_comment="Initial version"
> ... )
> ```

#### classmethod list(prompt_template_id)

List all versions of a prompt template.

- Parameters: prompt_template_id ( str ) – The ID of the prompt template.
- Returns: A list of versions for the template.
- Return type: List[PromptTemplateVersion]
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> versions = dr.genai.PromptTemplateVersion.list(
> ...     prompt_template_id="507f1f77bcf86cd799439011"
> ... )
> ```

#### classmethod list_all(prompt_template_ids=None)

List prompt template versions across multiple templates.

- Parameters: prompt_template_ids ( List[str] , optional ) – Filter versions to only those belonging to these prompt template IDs.
  If not provided, returns versions for all accessible templates.
- Returns: A list of prompt template versions.
- Return type: List[PromptTemplateVersion]
- Raises:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> # List all versions across all templates
> >>> versions = dr.genai.PromptTemplateVersion.list_all()
> >>> # List versions for specific templates
> >>> versions = dr.genai.PromptTemplateVersion.list_all(
> ...     prompt_template_ids=["template_id_1", "template_id_2"]
> ... )
> ```

#### render(variables=None, **kwargs)

Render the prompt text by substituting variables.

- Parameters:
- Returns: Rendered prompt text with variables substituted.
- Return type: str
- Raises: ValueError – If required variables are missing.

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> version = dr.genai.PromptTemplateVersion.get("template_id", "version_id")
> >>> version.render(name="Alice", issue="billing")
> 'Hello Alice, regarding billing...'
> ```

#### to_fstring()

Convert the prompt text from {{ variable }} format to Python f-string {variable} format.

This method transforms template placeholders from double-brace format ({{ variable }})
to single-brace format ({variable}), making the template compatible with Python
f-string syntax. Whitespace around variable names is automatically stripped.

- Returns: Prompt text with variables in f-string format.
- Return type: str
- Raises: ValueError – If prompt_text is None.

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> version = dr.genai.PromptTemplateVersion.get("template_id", "version_id")
> >>> # Original: "Hello {{ name }}, regarding {{ issue }}"
> >>> fstring_template = version.to_fstring()
> >>> # Result: "Hello {name}, regarding {issue}"
> >>> # Can now be used with f-string evaluation:
> >>> name = "Alice"
> >>> issue = "billing"
> >>> result = eval(f'f"{fstring_template}"')
> ```

### class datarobot.models.genai.prompt_template.Variable

A variable used in prompt templates.

- Variables:

---
