opik.PromptDataset
kedro_datasets_experimental.opik.PromptDataset ¶
PromptDataset(
filepath,
prompt_name,
credentials,
prompt_type="text",
sync_policy="local",
mode="sdk",
load_args=None,
save_args=None,
**opik_kwargs
)
Bases: AbstractDataset
Kedro dataset for managing prompts with Opik versioning and synchronisation.
This dataset provides seamless integration between local prompt files (JSON/YAML) and Opik's prompt management system, supporting version control, metadata tracking, and different synchronisation policies.
On save / load behaviour:
- On save: Creates a new version of the prompt in Opik with the local data.
- On load: Synchronises based on
sync_policyand returns either the raw Opik object (SDK mode) or a LangChainChatPromptTemplate(LangChain mode).
Sync policies:
- local: Local file takes precedence (default).
load_argsare ignored with a warning, since local files are the source of truth. - remote: Opik version takes precedence.
load_argsare respected if supported. - strict: Raises an error if local and remote differ.
load_argsare respected if supported
Examples:
Using catalog YAML configuration:
# Local sync policy - local files are source of truth
customer_prompt:
type: kedro_datasets_experimental.opik.PromptDataset
filepath: data/prompts/customer.json
prompt_name: customer_support_v1
prompt_type: chat
credentials: opik_credentials
sync_policy: local
mode: langchain
# Remote sync policy - Opik versions are source of truth
production_prompt:
type: kedro_datasets_experimental.opik.PromptDataset
filepath: data/prompts/production.yaml
prompt_name: customer_support_v1
sync_policy: remote
mode: sdk
Using Python API:
from kedro_datasets_experimental.opik import PromptDataset
# Create dataset for chat prompt
dataset = PromptDataset(
filepath="data/prompts/customer_support.json",
prompt_name="customer_support_v1",
prompt_type="chat",
credentials={
"api_key": "opik_...", # pragma: allowlist secret
"workspace": "my-workspace",
},
)
# Load prompt as LangChain ChatPromptTemplate
prompt_template = dataset.load()
formatted = prompt_template.format(question="How are you?")
# Save with metadata
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello, {question}"},
]
dataset.save(messages)
Parameters:
-
filepath(str | PathLike) –Local file path for storing prompt. Supports .json, .yaml, .yml extensions.
-
prompt_name(str) –Unique identifier for the prompt in Opik.
-
prompt_type(Literal['chat', 'text'], default:'text') –Either "chat" for message-based prompts or "text" for simple strings.
-
sync_policy(Literal['local', 'remote', 'strict'], default:'local') –How to handle conflicts between local and remote: - "local": Local file takes precedence (default) - "remote": Opik version takes precedence - "strict": Error if local and remote differ
-
mode(Literal['langchain', 'sdk'], default:'sdk') –Return type for load() method: - "sdk": Returns raw Opik prompt object (default) - "langchain": Returns ChatPromptTemplate object
-
credentials(dict[str, Any]) –Dictionary with Opik client configuration. Keys may include 'api_key', 'workspace', 'project_name', etc.
-
load_args(dict[str, Any] | None, default:None) –Dictionary with loading parameters. Currently reserved for future use when Opik supports version/label retrieval.
-
save_args(dict[str, Any] | None, default:None) –Dictionary with saving parameters. Keys may include: - metadata: Additional metadata to store with the prompt
-
**opik_kwargs(Any, default:{}) –Additional kwargs passed to Opik client initialisation.
Raises:
-
DatasetError–If required parameters are missing or invalid.
-
ImportError–If langchain is required but not installed.
Source code in kedro_datasets_experimental/opik/prompt_dataset.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
file_dataset
property
¶
file_dataset
Get appropriate Kedro dataset based on file extension (cached).
Returns:
-
Union[JSONDataset, YAMLDataset]–JSONDataset for .json files, YAMLDataset for .yaml/.yml files.
load ¶
load()
Load prompt with synchronisation logic.
Returns:
-
ChatPromptTemplate–If mode="langchain", ready-to-use LangChain template.
-
Any–If mode="sdk", raw Opik prompt object.
Raises:
-
DatasetError–If prompt cannot be loaded or has invalid format.
Source code in kedro_datasets_experimental/opik/prompt_dataset.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
preview ¶
preview()
Generate a JSON-compatible preview for Kedro-Viz.
Returns:
-
JSONPreview–A Kedro-Viz-compatible preview of the prompt.
Source code in kedro_datasets_experimental/opik/prompt_dataset.py
574 575 576 577 578 579 580 | |
save ¶
save(data)
Save prompt to Opik.
Parameters:
-
data(str | list[dict[str, str]]) –The prompt content to save. Can be string for text prompts or list of message dictionaries for chat prompts.
Raises:
-
DatasetError–If data format is invalid or save fails.
Source code in kedro_datasets_experimental/opik/prompt_dataset.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |