prompt-template-example

command module
v0.0.0-...-3308821 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Prompt Template Example

This example demonstrates the core features of LangChain Go's prompt template system.

Features Demonstrated

  1. Basic Templates - Simple variable substitution using Go templates
  2. Template Formats - Using different template syntaxes (Go, Jinja2, F-string)
  3. Partial Variables - Pre-filling some template variables
  4. Chat Templates - Creating structured chat prompts
  5. Optional Sanitization - HTML escaping for untrusted data

Running the Example

go run main.go

Key Concepts

Template Formats

LangChain Go supports three template formats:

  • Go Templates (default): {{ .variable }}
  • Jinja2: {{ variable }}
  • F-strings: {variable}
Security

By default, templates render without sanitization for maximum compatibility. When working with untrusted user input, enable sanitization:

result, err := prompts.RenderTemplate(
    template,
    prompts.TemplateFormatGoTemplate,
    data,
    prompts.WithSanitization(), // Enables HTML escaping
)
Partial Variables

Partial variables let you pre-fill template values:

template := prompts.PromptTemplate{
    Template: "{{.greeting}}, {{.name}}!",
    InputVariables: []string{"name"},
    PartialVariables: map[string]any{
        "greeting": "Hello",
    },
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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