Guide · Amazon Bedrock · Prompt Management
Bedrock Prompt CHAT vs TEXT Templates for MCP Servers — Few-Shot Examples, Variants, and Tool Configuration
Bedrock Prompt Management supports two templateType values: TEXT and CHAT. A TEXT template is a single string — the entire prompt in one field, with no explicit role boundaries. A CHAT template is a structured messages array with user and assistant roles, plus an optional system block. Use TEXT when the prompt is a simple instruction or question with dynamic variables. Use CHAT when you need a system message that sets the persona or constraints, or when you want to include few-shot examples — alternating user/assistant pairs that demonstrate the expected output format before the final user message. The variant model on a Bedrock prompt allows multiple named templates within a single prompt resource: a default variant for normal use, a strict variant for JSON-only output, a verbose variant for explanatory responses, and so on. At runtime, the MCP server selects the variant by name before rendering. This guide covers the CHAT template structure, few-shot example embedding, multi-variant prompt design, and storing tool definitions inside a CHAT variant. For the prompt creation and fetch APIs, see Prompt Management Overview. For variable rendering in both template types, see Prompt Variables. For versioning and CI/CD, see Prompt Versions.
TL;DR
Use TEXT for simple prompts; use CHAT when you need a system message or few-shot examples. CHAT templates require the last message to be from the user role. Variables ({{var}}) work in both template types and in every text field of a CHAT template including the system block. Use multiple variants on a single prompt to A/B test system prompts or offer different modes (strict/verbose/concise) without creating separate prompt resources.
TEXT vs CHAT: when to use each
| Criterion | TEXT | CHAT |
|---|---|---|
| Template structure | Single string field | system block + messages array with roles |
| System message / persona | Inline in the string (less reliable) | Dedicated system field (model gives it special weight) |
| Few-shot examples | Can embed as text, but awkward | Native: alternate user/assistant message pairs before final user turn |
| Output format control (JSON, Markdown, etc.) | Instruct in template text | Demonstrate in example assistant turns |
| Multi-turn conversation | Not supported natively | Include prior turns in messages array |
| Simplicity | Easier to write and read | More structure, more powerful |
The practical rule: start with TEXT for prototypes. Switch to CHAT when you observe that the model ignores role-specific instructions (persona, output format, constraints) that you embedded in the TEXT string, because the model does not treat the whole string as a system message — it processes it as a single user turn.
CHAT template structure
The templateConfiguration.chat object has three fields: system, messages, and inputVariables. The types map directly to what ConverseCommand expects after rendering:
import {
BedrockClient,
CreatePromptCommand,
} from "@aws-sdk/client-bedrock";
const client = new BedrockClient({ region: "us-east-1" });
await client.send(new CreatePromptCommand({
name: "mcp-entity-extractor",
defaultVariant: "default",
variants: [
{
name: "default",
templateType: "CHAT",
templateConfiguration: {
chat: {
// system: sets persona, constraints, output format instructions
system: [
{
text: "You are a precise entity extractor. "
+ "Return only valid JSON matching the schema {\"entities\": [{\"text\": string, \"type\": string}]}. "
+ "Never explain. Never add markdown fences.",
},
],
// messages: conversation turns, last must be role "user"
messages: [
// Few-shot example turn 1
{
role: "user",
content: [{ text: "Extract entities from: Amazon S3 and AWS Lambda are services." }],
},
{
role: "assistant",
content: [
{
text: JSON.stringify({
entities: [
{ text: "Amazon S3", type: "AWS_SERVICE" },
{ text: "AWS Lambda", type: "AWS_SERVICE" },
],
}),
},
],
},
// Few-shot example turn 2
{
role: "user",
content: [{ text: "Extract entities from: John Smith joined Acme Corp in 2023." }],
},
{
role: "assistant",
content: [
{
text: JSON.stringify({
entities: [
{ text: "John Smith", type: "PERSON" },
{ text: "Acme Corp", type: "ORGANIZATION" },
{ text: "2023", type: "DATE" },
],
}),
},
],
},
// Final user turn with variable — this is where the runtime input goes
{
role: "user",
content: [{ text: "Extract entities from: {{input_text}}" }],
},
],
inputVariables: [{ name: "input_text" }],
},
},
modelId: "anthropic.claude-3-5-haiku-20241022-v1:0",
inferenceConfiguration: {
text: {
temperature: 0.0,
maxTokens: 512,
},
},
},
],
}));
Key structural rules for CHAT templates:
- The
messagesarray must end with auserrole message. If the last message isassistant, the model will continue that message rather than generating a new response — producing confused output. - Few-shot examples (user/assistant pairs) go before the final user turn. The model sees the examples as prior conversation history.
- The
systemfield is optional. When present, it must be an array of{"text": string}objects — not a plain string. - Variables can appear in any
textfield — including system messages, example user messages, and the final user message. Render all of them before callingConverseCommand.
Using multiple variants for A/B testing and mode selection
A prompt resource can have up to 3 variants (the current service limit). Variants share the same prompt ID and version lifecycle — when you call CreatePromptVersionCommand, all variants are snapshotted together. This makes multi-variant prompts ideal for A/B testing: you change both variants, create one version, and deploy both simultaneously.
await client.send(new CreatePromptCommand({
name: "mcp-summarizer",
defaultVariant: "balanced",
variants: [
{
name: "balanced",
templateType: "CHAT",
templateConfiguration: {
chat: {
system: [
{ text: "You are a helpful assistant. Summarize clearly and concisely." },
],
messages: [
{
role: "user",
content: [
{ text: "Summarize in {{max_sentences}} sentences:\n\n{{content}}" },
],
},
],
inputVariables: [
{ name: "content" },
{ name: "max_sentences" },
],
},
},
modelId: "anthropic.claude-3-5-haiku-20241022-v1:0",
inferenceConfiguration: { text: { temperature: 0.3, maxTokens: 512 } },
},
{
name: "strict-json",
templateType: "CHAT",
templateConfiguration: {
chat: {
system: [
{
text: "You are a JSON summarizer. Output only valid JSON: "
+ "{\"summary\": string, \"key_points\": string[]}. No markdown. No explanation.",
},
],
messages: [
{
role: "user",
content: [{ text: "Summarize ({{max_sentences}} points max):\n\n{{content}}" }],
},
],
inputVariables: [
{ name: "content" },
{ name: "max_sentences" },
],
},
},
modelId: "anthropic.claude-3-5-haiku-20241022-v1:0",
inferenceConfiguration: { text: { temperature: 0.0, maxTokens: 256 } },
},
{
name: "verbose",
templateType: "CHAT",
templateConfiguration: {
chat: {
system: [
{
text: "You are a thorough analyst. Provide a detailed summary with context, "
+ "implications, and any caveats worth noting.",
},
],
messages: [
{
role: "user",
content: [{ text: "Analyze and summarize:\n\n{{content}}" }],
},
],
inputVariables: [{ name: "content" }],
},
},
modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0",
inferenceConfiguration: { text: { temperature: 0.5, maxTokens: 2048 } },
},
],
}));
Selecting variants at runtime in an MCP tool
The variant selection logic lives in the MCP tool handler. The calling agent can pass a mode hint, or the server can select based on its own heuristics:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import { getCachedVariant, renderChatTemplate } from "./prompt-utils.js";
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
const runtime = new BedrockRuntimeClient({ region: "us-east-1" });
const PROMPT_ID = process.env.SUMMARIZE_PROMPT_ID!;
const PROMPT_VERSION = process.env.SUMMARIZE_PROMPT_VERSION!;
const server = new McpServer({ name: "summary-tools", version: "1.0.0" });
server.tool(
"summarize",
{
content: z.string().min(1).max(100_000),
max_sentences: z.number().int().min(1).max(10).default(3),
mode: z
.enum(["balanced", "strict-json", "verbose"])
.default("balanced")
.describe("Output mode: 'balanced' for prose, 'strict-json' for structured data, 'verbose' for analysis"),
},
async ({ content, max_sentences, mode }) => {
const variant = await getCachedVariant(PROMPT_ID, PROMPT_VERSION, mode);
const variables: Record<string, string> = {
content: content.trim().slice(0, 50_000),
max_sentences: String(max_sentences),
};
const chatConfig = variant.templateConfiguration!.chat!;
const { system, messages } = renderChatTemplate(chatConfig, variables);
const result = await runtime.send(new ConverseCommand({
modelId: variant.modelId!,
system: system.length > 0 ? system : undefined,
messages,
inferenceConfig: {
temperature: variant.inferenceConfiguration?.text?.temperature ?? 0.3,
maxTokens: variant.inferenceConfiguration?.text?.maxTokens ?? 512,
},
}));
const text = result.output?.message?.content?.[0]?.text ?? "";
return { content: [{ type: "text", text }] };
},
);
await server.connect(new StdioServerTransport());
Notice that each variant can have a different modelId — the verbose variant uses Claude 3.5 Sonnet for higher quality while balanced and strict-json use Claude 3.5 Haiku for lower latency and cost. The calling agent selects the mode; the prompt manages which model is used for that mode. This is a clean separation: the MCP server is not hardcoding model IDs for each tool mode.
Embedding tool definitions in a CHAT variant
CHAT variants support a toolConfiguration field that lets you embed tool definitions inside the prompt resource itself. This is useful when the tool schema is tightly coupled to the prompt — changing the prompt often means changing the tool schema too, and versioning them together prevents drift:
await client.send(new CreatePromptCommand({
name: "mcp-data-extractor-with-tools",
variants: [
{
name: "default",
templateType: "CHAT",
templateConfiguration: {
chat: {
system: [
{
text: "You extract structured data from text. "
+ "Always use the extract_entities tool to return results.",
},
],
messages: [
{
role: "user",
content: [{ text: "Extract all entities from:\n\n{{input_text}}" }],
},
],
inputVariables: [{ name: "input_text" }],
toolConfiguration: {
tools: [
{
toolSpec: {
name: "extract_entities",
description: "Return structured entities extracted from the input text",
inputSchema: {
json: {
type: "object",
properties: {
entities: {
type: "array",
items: {
type: "object",
properties: {
text: { type: "string" },
type: { type: "string", enum: ["PERSON", "ORGANIZATION", "LOCATION", "DATE", "AWS_SERVICE"] },
confidence: { type: "number", minimum: 0, maximum: 1 },
},
required: ["text", "type"],
},
},
},
required: ["entities"],
},
},
},
},
],
toolChoice: { tool: { name: "extract_entities" } },
},
},
},
modelId: "anthropic.claude-3-5-haiku-20241022-v1:0",
inferenceConfiguration: { text: { temperature: 0.0, maxTokens: 1024 } },
},
],
}));
When rendering a CHAT template that includes toolConfiguration, you must extract it from the prompt variant and pass it to ConverseCommand. The rendering helper needs to handle this additional field:
import type { Tool, ToolChoice } from "@aws-sdk/client-bedrock-runtime";
import type { ChatPromptTemplateConfiguration } from "@aws-sdk/client-bedrock";
export function renderChatTemplateWithTools(
chatConfig: ChatPromptTemplateConfiguration,
variables: Record<string, string>,
): {
system: SystemContentBlock[];
messages: Message[];
toolConfig?: { tools: Tool[]; toolChoice?: ToolChoice };
} {
const { system, messages } = renderChatTemplate(chatConfig, variables);
const toolConfig = chatConfig.toolConfiguration
? {
tools: chatConfig.toolConfiguration.tools as Tool[],
toolChoice: chatConfig.toolConfiguration.toolChoice as ToolChoice | undefined,
}
: undefined;
return { system, messages, toolConfig };
}
// In the tool handler:
const { system, messages, toolConfig } = renderChatTemplateWithTools(chatConfig, variables);
const result = await runtime.send(new ConverseCommand({
modelId: variant.modelId!,
system: system.length > 0 ? system : undefined,
messages,
toolConfig,
inferenceConfig: { ... },
}));
When toolChoice forces a specific tool (as in the example above with toolChoice: { tool: { name: "extract_entities" } }), the model's response will be a toolUse content block rather than a text block. Handle the response accordingly:
const outputMessage = result.output?.message;
const content = outputMessage?.content ?? [];
for (const block of content) {
if (block.toolUse) {
// Structured tool call result
const entities = (block.toolUse.input as { entities: Array<{text: string; type: string}> }).entities;
return { content: [{ type: "text", text: JSON.stringify(entities, null, 2) }] };
}
}
CHAT template gotchas
Last message role constraint
The last message in the messages array must have role: "user". Ending with an assistant message is a common mistake when copying few-shot examples — if the last example pair ends with the assistant response, you must add one more user turn (the final variable-bearing message) after it. Some models will silently continue the assistant message rather than failing with a validation error.
Variables in system messages are rendered
If you include a variable in the system block (e.g. "You are a {{language}} language specialist"), you must pass that variable to the renderer — it is part of the inputVariables for the CHAT template. The system block is a text node like any other; the renderer does not distinguish between system and user content when scanning for placeholders.
Variant count limit
Bedrock Prompt Management currently supports up to 3 variants per prompt. If you need more than 3 response modes, consider whether some can share a variant with a mode-selection variable ({{mode}} in the system message) rather than separate variants.
Message count and context window
Few-shot examples consume tokens from the context window. Five example pairs with ~100 tokens each consume 500 tokens before the actual input. For long inputs, this can push the prompt above the model's context limit. Keep few-shot examples short and representative. If the model learns the pattern from 2–3 examples, adding 10 more hurts cost and latency without improving accuracy.
Related pages in this arc
- Prompt Management Overview — CreatePrompt, GetPrompt, prompt anatomy, IAM, startup caching
- Prompt Variables — {{variable}} syntax, rendering TEXT and CHAT templates, variable validation
- Prompt Versions — CreatePromptVersionCommand, immutability, CI/CD workflow, rollback
For tool use patterns beyond prompt templates, see Bedrock Converse API. For structured output via forced tool calls, see Bedrock Agents.