Implementation:Wandb Weave Prompt Ref Get
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Prompt_Engineering, Object_Storage |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete tool for retrieving published prompts and formatting them with variables provided by the Wandb Weave library.
Description
weave.ref() creates an ObjectRef pointing to a published prompt. ref.get() deserializes it. prompt.format(**kwargs) applies template variable substitution. The format_message_with_template_vars helper recursively processes nested message content.
Usage
Use weave.ref("prompt_name").get() to load a published prompt, then call .format() with your template variables.
Code Reference
Source Location
- Repository: wandb/weave
- File: weave/trace/api.py
- Lines: L181-207 (ref)
- File: weave/prompt/prompt.py
- Lines: L96-97 (StringPrompt.format), L180-181 (MessagesPrompt.format), L108-161 (format_message_with_template_vars)
Signature
def ref(location: str) -> ObjectRef:
"""Creates a Ref to an existing Weave object.
Args:
location: URI, "name:version", or "name" (resolves to latest).
Returns:
ObjectRef to the prompt.
"""
# Then call:
# prompt = ref.get() # Deserializes the Prompt object
# result = prompt.format(**kwargs) # Applies variable substitution
Import
import weave
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| location | str | Yes | Prompt name, "name:version", or full URI |
| **kwargs | Any | Varies | Template variables for format() |
Outputs
| Name | Type | Description |
|---|---|---|
| ref.get() | Prompt | Deserialized Prompt object |
| prompt.format() | str or list | Formatted prompt with variables substituted |
Usage Examples
Retrieve and Format
import weave
weave.init("my-team/my-project")
# Load latest version
prompt = weave.ref("translation_prompt").get()
result = prompt.format(text="Hello", language="French")
print(result)
# Load specific version
prompt_v1 = weave.ref("translation_prompt:abc123").get()
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment