Skip to main content

Crate prompeta

Crate prompeta 

Source
Expand description

§prompeta 🎺

Declarative prompt engineering with semantic roles and pluggable rendering strategies.

Instead of building prompts as strings, you declare content with semantic roles (instruction, context, focus, constraint, example, schema) and a PromptStrategy renders the final text using best-practice prompt engineering.

§Quick start

use prompeta::{Prompt, ContentRole};

let prompt = Prompt::new()
    .instruction("You are a helpful assistant.")
    .context("User profile", "Name: Alice, Role: Engineer")
    .focus("Current task", "Debug the authentication module")
    .constraint("Do not modify production database")
    .schema(serde_json::json!({
        "diagnosis": "string",
        "fix": "string",
        "confidence": "float 0-1"
    }));

// Renders using the default ClaudeStrategy
let text = prompt.to_string();

§Key concepts

  • Content roles — Each block of content has a semantic role that tells the renderer how to format and order it.
  • Pluggable strategies — The PromptStrategy trait lets you swap rendering logic per model family. A ClaudeStrategy is provided by default.
  • Budget trimming — Prompt::trim_to_budget removes lowest-priority blocks until the output fits within a character budget.
  • Tag-based manipulation — Block-level tags let you surgically remove or replace content without position-dependent code.

Structs§

Block
A content block with semantic metadata.
ClaudeStrategy
Default strategy optimized for Claude models.
Prompt
A declarative prompt: a collection of semantically-typed blocks.

Enums§

ContentRole
Semantic role of a content block within a prompt.

Traits§

PromptStrategy
Pluggable rendering algorithm for converting a Prompt to text.