prompt

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package prompt parses .prompt templates.

A .prompt file is YAML frontmatter followed by freeform text:

---
name: Customer Support Classifier
version: 2.1.0
models:
  - gpt-4o-mini
variables:
  - user_query
---
You are an expert customer support agent.
Analyze the user query: {{ user_query }}

Index

Constants

This section is empty.

Variables

View Source
var ErrMalformedFrontmatter = errors.New("malformed frontmatter: missing closing `---`")

ErrMalformedFrontmatter is returned when the frontmatter block is not terminated.

View Source
var ErrNoFrontmatter = errors.New("no frontmatter found (expected a leading `---` block)")

ErrNoFrontmatter is returned when a file has no `---` delimiter.

Functions

func Render added in v1.14.0

func Render(t *Template, body string) (string, error)

Render re-serializes a template's frontmatter (name/version/models/ variables) followed by the given body. This normalizes frontmatter formatting rather than preserving an original file's exact YAML layout.

Types

type Template

type Template struct {
	Name        string   `yaml:"name"`
	Version     string   `yaml:"version"`
	Models      []string `yaml:"models"`
	Variables   []string `yaml:"variables"`
	Body        string   `yaml:"-"`
	RawVariable string   `yaml:"variableSet"` // any additional user keys are ignored
}

Template is a parsed .prompt file.

func Parse

func Parse(src []byte) (*Template, error)

Parse splits frontmatter from the body, parses the YAML, and extracts every {{ variable }} referenced in the body.

func (*Template) Sections

func (t *Template) Sections() []string

Sections splits the body into paragraph-sized sections on blank lines.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL