Skip to content

Prompting

Chat

class datarobot.models.genai.chat.Chat

Metadata for a DataRobot GenAI chat.

Variables

Attribute Type Description
id str The chat ID.
name str The chat name.
llm_blueprint_id str The ID of the LLM blueprint associated with the chat.
is_frozen bool Checks whether the chat is frozen. Prompts cannot be submitted to frozen chats.
creation_date str The date when the chat was created.
creation_user_id str The ID of the creating user.
warning str or None, optional The warning about the contents of the chat.
prompts_count int The number of chat prompts in the chat.

create()

classmethod create()

Creates a new chat.

Parameters

Parameter Type Description
name str The chat name.
llm_blueprint LLMBlueprint or str The LLM blueprint associated with the created chat, either LLM blueprint or ID.

Returns

Returns Description
chat The created chat.

Return type: Chat

get()

classmethod get()

Retrieve a single chat.

Parameters

Parameter Type Description
chat Chat or str The chat you want to retrieve. Accepts chat or chat ID.

Returns

Returns Description
chat The requested chat.

Return type: Chat

list()

classmethod list()

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

Parameter Type Description
llm_blueprint Optional[Union[LLMBlueprint, str]], optional Returns only those chats associated with a particular LLM blueprint, specified by either the entity or the ID.
sort Optional[str] The property to sort chats by. Prefix the attribute name with a dash ( - ) to sort responses in descending order, (for example, ‘-name’). Supported options are listed in ListChatsSortQueryParams, but the values can differ depending on platform version. The default sort parameter is None, which results in chats returning in order of creation time, descending.

Returns

Returns Description
chats Returns a list of chats.

Return type: list[Chat]

delete()

method delete()

Delete the single chat.

Return type: None

update()

method update()

Update the chat.

Parameters

Parameter Type Description
name str The new name for the chat.

Returns

Returns Description
chat The updated chat.

Return type: Chat

ChatPrompt

class datarobot.models.genai.chat_prompt.ChatPrompt

Metadata for a DataRobot GenAI chat prompt.

Variables

Attribute Type Description
id str Chat prompt ID.
text str The prompt text.
llm_blueprint_id str ID of the LLM blueprint associated with the chat prompt.
llm_id str ID of the LLM type. This must be one of the IDs returned by LLMDefinition.list for this user.
llm_settings dict or None The LLM settings for the LLM blueprint. The specific keys allowed and the constraints on the values are defined in the response from LLMDefinition.list, but this typically has dict fields. Either:- system_prompt - The system prompt that influences the LLM responses. - max_completion_length - The maximum number of tokens in the completion. - temperature - Controls the variability in the LLM response. - top_p - Sets whether the model considers next tokens with top_p probability mass. or - system_prompt - The system prompt that influences the LLM responses. - validation_id - The ID of the external model LLM validation. - external_llm_context_size - The external LLM’s context size, in tokens, for external model-based LLM blueprints.
creation_date str The date the chat prompt was created.
creation_user_id str ID of the creating user.
vector_database_id str or None ID of the vector database associated with the LLM blueprint, if any.
vector_database_settings VectorDatabaseSettings or None The settings for the vector database associated with the LLM blueprint, if any.
result_metadata ResultMetadata or None Metadata for the result of the chat prompt submission.
result_text str or None The result text from the chat prompt submission.
confidence_scores ConfidenceScores or None The confidence scores if there is a vector database associated with the chat prompt.
citations list[Citation] List of citations from text retrieved from the vector database, if any.
execution_status str The execution status of the chat prompt.
chat_id Optional[str] ID of the chat associated with the chat prompt.
chat_context_id Optional[str] The ID of the chat context for the chat prompt.
chat_prompt_ids_included_in_history Optional[list[str]] The IDs of the chat prompts included in the chat history for this chat prompt.
metadata_filter Optional[Dict[str, Any] \| None] The metadata filter to apply to the vector database. Supports:- None or empty dict (no filters): Considers all documents - Multiple field filters (implicit AND): {“a”: 1, “b”: “b”} - Comparison operators: {“field”: {“\(gt”: 5}} - Logical operators: {“\)and”: […], “$or”: […]} - Nested combinations of the above Comparison operators:- $eq: equal to (string, int, float, bool) - $ne: not equal to (string, int, float, bool) - $gt: greater than (int, float) - $gte: greater than or equal to (int, float) - $lt: less than (int, float) - $lte: less than or equal to (int, float) - $in: a value is in list (string, int, float, bool) - $nin: a value is not in list (string, int, float, bool) - $contains: a string contains a value (string) - $not_contains: a string does not contain a value (string)

create()

classmethod create()

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

Parameters

Parameter Type Description
text str The prompt text.
llm_blueprint LLMBlueprint or str or None, optional The LLM blueprint associated with the created chat prompt, either LLMBlueprint or LLM blueprint ID.
chat Chat or str or None, optional The chat associated with the created chat prompt, either Chat or chat ID.
llm LLMDefinition, str, or None, optional The LLM to use for the chat prompt, either LLMDefinition or LLM blueprint ID.
llm_settings dict or None LLM settings to use for the chat prompt. The specific keys allowed and the constraints on the values are defined in the response from LLMDefinition.list but this typically has dict fields:- system_prompt - The system prompt that tells the LLM how to behave. - max_completion_length - The maximum number of tokens in the completion. - temperature - Controls the variability in the LLM response. - top_p - Whether the model considers next tokens with top_p probability mass. Or - system_prompt - The system prompt that tells the LLM how to behave. - validation_id - The ID of the custom model LLM validation for custom model LLM blueprints.
vector_database VectorDatabase, str, or None, optional The vector database to use with this chat prompt submission, either VectorDatabase or vector database ID.
vector_database_settings VectorDatabaseSettings or None, optional Settings for the vector database, if any.
wait_for_completion bool If set to True, chat prompt result response limit is up to 10 minutes, raising a timeout error after that. Otherwise, check current status by using ChatPrompt.get with returned ID.
metadata_filter Optional[Dict[str, Any] \| None] The metadata filter to apply to the vector database. Supports:- None or empty dict (no filters): Considers all documents - Multiple field filters (implicit AND): {“a”: 1, “b”: “b”} - Comparison operators: {“field”: {“\(gt”: 5}} - Logical operators: {“\)and”: […], “$or”: […]} - Nested combinations of the above Comparison operators:- $eq: equal to (string, int, float, bool) - $ne: not equal to (string, int, float, bool) - $gt: greater than (int, float) - $gte: greater than or equal to (int, float) - $lt: less than (int, float) - $lte: less than or equal to (int, float) - $in: a value is in list (string, int, float, bool) - $nin: a value is not in list (string, int, float, bool) - $contains: a string contains a value (string) - $not_contains: a string does not contain a value (string)

Returns

Returns Description
chat_prompt The created chat prompt.

Return type: ChatPrompt

update()

method update()

Update the chat prompt.

Parameters

Parameter Type Description
custom_metrics Optional[list[MetricMetadata]], optional The new custom metrics to add to the chat prompt.
feedback_metadata Optional[FeedbackMetadata], optional The new feedback to add to the chat prompt.

Returns

Returns Description
chat_prompt The updated chat prompt.

Return type: ChatPrompt

get()

classmethod get()

Retrieve a single chat prompt.

Parameters

Parameter Type Description
chat_prompt ChatPrompt or str The chat prompt you want to retrieve, either ChatPrompt or chat prompt ID.

Returns

Returns Description
chat_prompt The requested chat prompt.

Return type: ChatPrompt

list()

classmethod list()

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

Parameter Type Description
llm_blueprint Optional[Union[LLMBlueprint, str]], optional The returned chat prompts are filtered to those associated with a specific LLM blueprint if it is specified. Accepts either LLMBlueprint or LLM blueprint ID.
playground Optional[Union[Playground, str]], optional The returned chat prompts are filtered to those associated with a specific playground if it is specified. Accepts either Playground or playground ID.
chat Optional[Union[Chat, str]], optional The returned chat prompts are filtered to those associated with a specific chat if it is specified. Accepts either Chat or chat ID.

Returns

Returns Description
chat_prompts A list of chat prompts available to the user.

Return type: list[ChatPrompt]

delete()

method delete()

Delete the single chat prompt.

Return type: None

create_llm_blueprint()

method create_llm_blueprint()

Create a new LLM blueprint from an existing chat prompt.

Parameters

Parameter Type Description
name str LLM blueprint name.
description Optional[str] Description of the LLM blueprint, by default “”.

Returns

Returns Description
llm_blueprint The created LLM blueprint.

Return type: LLMBlueprint

ComparisonChat

class datarobot.models.genai.comparison_chat.ComparisonChat

Metadata for a DataRobot GenAI comparison chat.

Variables

Attribute Type Description
id str The comparison chat ID.
name str The comparison chat name.
playground_id str The ID of the playground associated with the comparison chat.
creation_date str The date when the comparison chat was created.
creation_user_id str The ID of the creating user.

create()

classmethod create()

Creates a new comparison chat.

Parameters

Parameter Type Description
name str The comparison chat name.
playground Playground or str The playground associated with the created comparison chat, either Playground or playground ID.

Returns

Returns Description
comparison_chat The created comparison chat.

Return type: ComparisonChat

get()

classmethod get()

Retrieve a single comparison chat.

Parameters

Parameter Type Description
comparison_chat ComparisonChat or str The comparison chat you want to retrieve. Accepts ComparisonChat or comparison chat ID.

Returns

Returns Description
comparison_chat The requested comparison chat.

Return type: ComparisonChat

list()

classmethod list()

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

Parameter Type Description
playground Optional[Union[Playground, str]], optional Returns only those comparison chats associated with a particular playground, specified by either the Playground or the playground ID.
sort Optional[str] The property to sort comparison chats by. Prefix the attribute name with a dash ( - ) to sort responses in descending order, (for example, ‘-name’). Supported options are listed in ListComparisonChatsSortQueryParams, but the values can differ depending on platform version. The default sort parameter is None, which results in comparison chats returning in order of creation time, descending.

Returns

Returns Description
comparison_chats Returns a list of comparison chats.

Return type: list[ComparisonChat]

delete()

method delete()

Delete the single comparison chat.

Return type: None

update()

method update()

Update the comparison chat.

Parameters

Parameter Type Description
name str The new name for the comparison chat.

Returns

Returns Description
comparison_chat The updated comparison chat.

Return type: ComparisonChat

ComparisonPrompt

class datarobot.models.genai.comparison_prompt.ComparisonPrompt

Metadata for a DataRobot GenAI comparison prompt.

Variables

Attribute Type Description
id str Comparison prompt ID.
text str The prompt text.
results list[ComparisonPromptResult] The list of results for individual LLM blueprints that are part of the comparison prompt.
creation_date str The date when the playground was created.
creation_user_id str ID of the creating user.
comparison_chat_id str The ID of the comparison chat this comparison prompt is associated with.
metadata_filter Optional[Dict[str, Any] \| None] The metadata filter to apply to the vector database. Supports:- None or empty dict (no filters): Considers all documents - Multiple field filters (implicit AND): {“a”: 1, “b”: “b”} - Comparison operators: {“field”: {“\(gt”: 5}} - Logical operators: {“\)and”: […], “$or”: […]} - Nested combinations of the above Comparison operators:- $eq: equal to (string, int, float, bool) - $ne: not equal to (string, int, float, bool) - $gt: greater than (int, float) - $gte: greater than or equal to (int, float) - $lt: less than (int, float) - $lte: less than or equal to (int, float) - $in: a value is in list (string, int, float, bool) - $nin: a value is not in list (string, int, float, bool) - $contains: a string contains a value (string) - $not_contains: a string does not contain a value (string)

update()

method update()

Update the comparison prompt.

Parameters

Parameter Type Description
additional_llm_blueprints list[LLMBlueprint or str] The additional LLM blueprints you want to submit the comparison prompt.

Returns

Returns Description
comparison_prompt The updated comparison prompt.

Return type: ComparisonPrompt

create()

classmethod create()

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

Parameters

Parameter Type Description
llm_blueprints list[LLMBlueprint or str] The LLM blueprints associated with the created comparison prompt. Accepts LLM blueprints or IDs.
text str The prompt text.
comparison_chat Optional[ComparisonChat or str], optional The comparison chat to add the comparison prompt to. Accepts ComparisonChat or comparison chat ID.
wait_for_completion bool If set to True code will wait for the chat prompt job to complete before returning the result (up to 10 minutes, raising timeout error after that). Otherwise, you can check current status by using ChatPrompt.get with returned ID.
metadata_filter Optional[Dict[str, Any] \| None] The metadata filter to apply to the vector database. Supports:- None or empty dict (no filters): Considers all documents - Multiple field filters (implicit AND): {“a”: 1, “b”: “b”} - Comparison operators: {“field”: {“\(gt”: 5}} - Logical operators: {“\)and”: […], “$or”: […]} - Nested combinations of the above Comparison operators:- $eq: equal to (string, int, float, bool) - $ne: not equal to (string, int, float, bool) - $gt: greater than (int, float) - $gte: greater than or equal to (int, float) - $lt: less than (int, float) - $lte: less than or equal to (int, float) - $in: a value is in list (string, int, float, bool) - $nin: a value is not in list (string, int, float, bool) - $contains: a string contains a value (string) - $not_contains: a string does not contain a value (string)

Returns

Returns Description
comparison_prompt The created comparison prompt.

Return type: ComparisonPrompt

get()

classmethod get()

Retrieve a single comparison prompt.

Parameters

Parameter Type Description
comparison_prompt str The comparison prompt you want to retrieve. Accepts entity or ID.

Returns

Returns Description
comparison_prompt The requested comparison prompt.

Return type: ComparisonPrompt

list()

classmethod list()

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

Parameters

Parameter Type Description
llm_blueprints Optional[List[Union[LLMBlueprint, str]]], optional The returned comparison prompts are only those associated with the specified LLM blueprints. Accepts either LLMBlueprint or LLM blueprint ID.
comparison_chat Optional[Union[ComparisonChat, str]], optional The returned comparison prompts are only those associated with the specified comparison chat. Accepts either ComparisonChat or comparison chat ID.

Returns

Returns Description
comparison_prompts A list of comparison prompts available to the user that use the specified LLM blueprints.

Return type: list[ComparisonPrompt]

delete()

method delete()

Delete the single comparison prompt.

Return type: None

Playground

class datarobot.models.genai.playground.Playground

Metadata for a DataRobot GenAI playground.

Variables

Attribute Type Description
id str Playground ID.
name str Playground name.
description str Description of the playground.
use_case_id str Linked use case ID.
creation_date str The date when the playground was created.
creation_user_id str ID of the creating user.
last_update_date str Date when the playground was most recently updated.
last_update_user_id str ID of the user who most recently updated the playground.
saved_llm_blueprints_count int Number of saved LLM blueprints in the playground.
llm_blueprints_count int Number of LLM blueprints in the playground.
user_name str The name of the user who created the playground.
playground_type (Optional[PlaygroundType])

create()

classmethod create()

Create a new playground.

Parameters

Parameter Type Description
name str Playground name.
description Optional[str] Description of the playground, by default “”.
use_case Optional[Union[UseCase, str]], optional Use case to link to the created playground.
copy_insights CopyInsightsRequest, optional If present, copies insights from the source playground to the created playground.

Returns

Returns Description
playground The created playground.

Return type: Playground

get()

classmethod get()

Retrieve a single playground.

Parameters

Parameter Type Description
playground_id str The ID of the playground you want to retrieve.

Returns

Returns Description
playground The requested playground.

Return type: Playground

list()

classmethod list()

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

Parameter Type Description
use_case Optional[UseCaseLike], optional The returned playgrounds are filtered to those associated with a specific Use Case or Cases if specified or can be inferred from the Context. Accepts either the entity or the ID.
search Optional[str] String for filtering playgrounds. Playgrounds that contain the string in name will be returned. If not specified, all playgrounds will be returned.
sort Optional[str] Property to sort playgrounds by. Prefix the attribute name with a dash to sort in descending order, e.g., sort=’-creationDate’. Currently supported options are listed in ListPlaygroundsSortQueryParams but the values can differ with different platform versions. By default, the sort parameter is None which will result in playgrounds being returned in order of creation time descending.

Returns

Returns Description
playgrounds A list of playgrounds available to the user.

Return type: list[Playground]

update()

method update()

Update the playground.

Parameters

Parameter Type Description
name str The new name for the playground.
description str The new description for the playground.

Returns

Returns Description
playground The updated playground.

Return type: Playground

delete()

method delete()

Delete the playground.

Return type: None

PromptType

class datarobot.enums.PromptType

Supported LLM blueprint prompting types.

UserLimits

class datarobot.models.genai.user_limits.UserLimits

Counts for user limits for LLM APIs and vector databases.

get_vector_database_count()

classmethod get_vector_database_count()

Get the count of vector databases for the user.

Return type: APIObject

get_llm_requests_count()

classmethod get_llm_requests_count()

Get the count of LLMs requests made by the user.

Return type: APIObject

ResultMetadata

class datarobot.models.genai.chat_prompt.ResultMetadata

Metadata for the result of a chat prompt submission.

Variables

Attribute Type Description
output_token_count int The number of tokens in the output.
input_token_count int The number of tokens in the input. This includes the chat history and documents retrieved from a vector database, if any.
total_token_count int The total number of tokens processed.
estimated_docs_token_count int The estimated number of tokens from the documents retrieved from a vector database, if any.
latency_milliseconds int The latency of the chat prompt submission in milliseconds.
feedback_result FeedbackResult The lists of user_ids providing positive and negative feedback.
metrics MetricMetadata The evaluation metrics for this prompt.
final_prompt Optional[Union[str, dict]], optional Representation of the final prompt sent to the LLM.
error_message str or None, optional The error message from the LLM response.
cost float or None, optional The cost of the chat prompt submission.

PromptTrace

class datarobot.models.genai.prompt_trace.PromptTrace

Prompt trace contains aggregated information about a prompt execution.

Variables

Attribute Type Description
timestamp str The timestamp of the trace (ISO 8601 formatted).
user dict The user who submitted the prompt.
chat_prompt_id str The ID of the chat prompt associated with the trace.
use_case_id str The ID of the Use Case the playground is in.
comparison_prompt_id str The ID of the comparison prompts associated with the trace.
llm_blueprint_id str The ID of the LLM blueprint that the prompt was submitted to.
llm_blueprint_name str The name of the LLM blueprint.
llm_name str The name of the LLM in the LLM blueprint.
llm_vendor str The vendor name of the LLM.
llm_license str What type of license the LLM has.
llm_settings dict or None The LLM settings for the LLM blueprint. The specific keys allowed and the constraints on the values are defined in the response from LLMDefinition.list, but this typically has dict fields. Either:- system_prompt - The system prompt that influences the LLM responses. - max_completion_length - The maximum number of tokens in the completion. - temperature - Controls the variability in the LLM response. - top_p - Sets whether the model considers next tokens with top_p probability mass. or - system_prompt - The system prompt that influences the LLM responses. - validation_id - The ID of the external model LLM validation. - external_llm_context_size - The external LLM’s context size, in tokens, for external model-based LLM blueprints.
chat_name str or None The name of the chat associated with the Trace.
chat_id str or None The ID of the chat associated with the Trace.
vector_database_id str or None ID of the vector database associated with the LLM blueprint, if any.
vector_database_settings VectorDatabaseSettings or None The settings for the vector database associated with the LLM blueprint, if any.
result_metadata ResultMetadata or None Metadata for the result of the prompt submission.
result_text str or None The result text from the prompt submission.
confidence_scores ConfidenceScores or None The confidence scores if there is a vector database associated with the prompt.
text str The prompt text submitted to the LLM.
execution_status str The execution status of the chat prompt.
prompt_type str or None The type of prompting strategy, for example history aware.
evaluation_dataset_configuration_id str or None The ID of the evaluation dataset configuration associated with the trace.
warning str or None Any warnings associated with the trace.

list()

classmethod list()

List all prompt traces for a playground.

Parameters

Parameter Type Description
playground str The ID of the playground to list prompt traces for.

Returns

Returns Description
prompt_traces List of prompt traces for the playground.

Return type: list[PromptTrace]

export_to_ai_catalog()

classmethod export_to_ai_catalog()

Export prompt traces to AI Catalog as a CSV.

Parameters

Parameter Type Description
playground str The ID of the playground to export prompt traces for.

Returns

Returns Description
status_url The URL where the status of the job can be monitored

Return type: str

TraceMetadata

class datarobot.models.genai.prompt_trace.TraceMetadata

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

Variables

Attribute Type Description
users list[dict] The users who submitted the prompt.

get()

classmethod get()

Get trace metadata for a playground.

Parameters

Parameter Type Description
playground str The ID of the playground to get trace metadata for.

Returns

Returns Description
trace_metadata The trace metadata for the playground.

Return type: TraceMetadata

PromptTemplate

class datarobot.models.genai.prompt_template.PromptTemplate

A prompt template that can have multiple versions.

Variables

Attribute Type Description
id str Prompt template ID.
name str Prompt template name.
description str Description of the prompt template.
creation_date str ISO-8601 formatted timestamp of when the template was created.
creation_user_id str ID of the user who created the template.
last_update_date str ISO-8601 formatted timestamp of when the template was last updated.
last_update_user_id str ID of the user who last updated the template.
user_name str Name of the user who created the template.
version_count int Number of versions this template has.

create()

classmethod create()

Create a new prompt template.

Parameters

Parameter Type Description
name str Name of the prompt template.
description str, optional Description of the prompt template.

Returns

Returns Description
The created prompt template.

Return type: PromptTemplate

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> import datarobot as dr
>>> template = dr.genai.PromptTemplate.create(
...     name="Customer Support",
...     description="Template for support responses"
... )

list()

classmethod list()

List all prompt templates available to the user.

Parameters

Parameter Type Description
sort str, optional Prefix the attribute name with a dash to sort in descending order, e.g., sort=’-creationDate’.
search str, optional Filter templates by name containing this string.

Returns

Returns Description
A list of prompt templates.

Return type: List[PromptTemplate]

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> import datarobot as dr
>>> templates = dr.genai.PromptTemplate.list(sort="-creationDate")

get()

classmethod get()

Get a prompt template by ID.

Parameters

Parameter Type Description
prompt_template_id str The ID of the prompt template to retrieve.

Returns

Returns Description
The requested prompt template.

Return type: PromptTemplate

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> import datarobot as dr
>>> template = dr.genai.PromptTemplate.get("507f1f77bcf86cd799439011")

create_version()

method create_version()

Create a new version of this prompt template.

Parameters

Parameter Type Description
prompt_text str The prompt text with variables in {{ variable }} format.
variables List[Variable], optional List of Variable objects defining the variables used in the prompt template. Defaults to None, which sends an empty list to the API.
commit_comment str, optional Comment describing this version.

Returns

Returns Description
The created version.

Return type: PromptTemplateVersion

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

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()

method list_versions()

List all versions of this prompt template.

Returns

Returns Description
A list of versions for this template.

Return type: List[PromptTemplateVersion]

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> versions = template.list_versions()

get_version()

method get_version()

Get a specific version of this prompt template.

Parameters

Parameter Type Description
prompt_template_version_id str The ID of the version to retrieve.

Returns

Returns Description
The requested version.

Return type: PromptTemplateVersion

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> import datarobot as dr
>>> template = dr.genai.PromptTemplate.get("507f1f77bcf86cd799439011")
>>> version = template.get_version("507f1f77bcf86cd799439012")

get_latest_version()

method get_latest_version()

Get the latest version of this prompt template.

Returns

Returns Description
The latest version, or None if no versions exist.

Return type: Optional[PromptTemplateVersion]

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

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

PromptTemplateVersion

class datarobot.models.genai.prompt_template.PromptTemplateVersion

A specific version of a prompt template.

Variables

Attribute Type Description
id str Version ID.
prompt_template_id str ID of the parent prompt template.
prompt_text str The prompt text with variables in {{ variable }} format.
commit_comment str Comment describing this version.
version int Version number.
variables List[Variable] List of variables used in the prompt.
creation_date str ISO-8601 formatted timestamp of when the version was created.
creation_user_id str ID of the user who created the version.
user_name str Name of the user who created the version.

get()

classmethod get()

Get a specific prompt template version by ID.

Parameters

Parameter Type Description
prompt_template_id str The ID of the prompt template.
prompt_template_version_id str The ID of the version to retrieve.

Returns

Returns Description
The requested prompt template version.

Return type: PromptTemplateVersion

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> import datarobot as dr
>>> version = dr.genai.PromptTemplateVersion.get("prompt_template_id", "prompt_template_version_id")

create()

classmethod create()

Create a new version of a prompt template.

Parameters

Parameter Type Description
prompt_template_id str The ID of the prompt template.
prompt_text str The prompt text with variables in {{ variable }} format.
variables List[Variable], optional List of Variable objects defining the variables used in the prompt template.
commit_comment str, optional Comment describing this version.

Returns

Returns Description
The created version.

Return type: PromptTemplateVersion

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

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"
... )

list()

classmethod list()

List all versions of a prompt template.

Parameters

Parameter Type Description
prompt_template_id str The ID of the prompt template.

Returns

Returns Description
A list of versions for the template.

Return type: List[PromptTemplateVersion]

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

Examples

>>> import datarobot as dr
>>> versions = dr.genai.PromptTemplateVersion.list(
...     prompt_template_id="507f1f77bcf86cd799439011"
... )

list_all()

classmethod list_all()

List prompt template versions across multiple templates.

Parameters

Parameter Type Description
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

Returns Description
A list of prompt template versions.

Return type: List[PromptTemplateVersion]

Raises

Exception Description
datarobot.errors.ClientError If the server responded with 4xx status.
datarobot.errors.ServerError If the server responded with 5xx status.

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()

method render()

Render the prompt text by substituting variables.

Parameters

Parameter Type Description
variables Optional[Dict[str, Any]] Dictionary of variable names to values. * **kwargs (Any) – Variable values as keyword arguments. These override values in the variables dict.

Returns

Returns Description
Rendered prompt text with variables substituted.

Return type: str

Raises

Exception Description
ValueError If required variables are missing.

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()

method 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

Returns Description
Prompt text with variables in f-string format.

Return type: str

Raises

Exception Description
ValueError If prompt_text is None.

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}"')

Variable

class datarobot.models.genai.prompt_template.Variable

A variable used in prompt templates.

Variables

Attribute Type Description
name str Variable name.
type str Variable type (e.g., “str”, “int”).
description str Description of the variable.