examples/prompt-template-example/README.md
This example demonstrates the core features of LangChain Go's prompt template system.
go run main.go
LangChain Go supports three template formats:
{{ .variable }}{{ variable }}{variable}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 let you pre-fill template values:
template := prompts.PromptTemplate{
Template: "{{.greeting}}, {{.name}}!",
InputVariables: []string{"name"},
PartialVariables: map[string]any{
"greeting": "Hello",
},
}