Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Wandb Weave Prompt Iterate Pattern

From Leeroopedia
Revision as of 14:02, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Wandb_Weave_Prompt_Iterate_Pattern.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Prompt_Engineering, Versioning
Last Updated 2026-02-14 00:00 GMT

Overview

Pattern documentation for iterating on prompts through publish-modify-republish cycles using the Wandb Weave library.

Description

This is a Pattern Doc documenting the iterative prompt development workflow. It uses weave.publish() repeatedly with the same name to create new versions. The same publish API from Object Publishing is reused; the pattern is in the workflow, not the API.

Usage

Follow this pattern throughout the prompt engineering lifecycle to maintain a complete version history of all prompt iterations.

Code Reference

Source Location

  • Repository: wandb/weave
  • File: weave/trace/api.py
  • Lines: L118-178 (publish — same as Prompt Publishing)

Signature

# The pattern uses the same publish() API:
def publish(obj: Any, name: str | None = None) -> ObjectRef:
    """Each publish with the same name creates a new version
    if the content hash differs."""

Import

import weave

I/O Contract

Inputs

Name Type Required Description
obj Prompt Yes Modified prompt object
name str Yes Same name as previous version

Outputs

Name Type Description
return ObjectRef Reference with new digest for the updated version

Usage Examples

Iterate on a Prompt

import weave

weave.init("my-team/my-project")

# Version 1
prompt_v1 = weave.StringPrompt(content="Translate '{text}' to {language}.")
ref1 = weave.publish(prompt_v1, name="translation_prompt")

# Version 2 - improved
prompt_v2 = weave.StringPrompt(
    content="You are an expert translator. Translate the following text to {language}:\n\n{text}"
)
ref2 = weave.publish(prompt_v2, name="translation_prompt")

# Access specific versions
latest = weave.ref("translation_prompt").get()       # v2
v1 = weave.ref(f"translation_prompt:{ref1._digest}").get()  # v1

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment