Guide · Amazon Bedrock Agents · Prompt Override & Custom Orchestration
Bedrock Agents Prompt Override Configuration for MCP Servers — Custom Orchestration, Pre/Post Processing, and Guardrails
Amazon Bedrock Agents provides a default orchestration loop that handles pre-processing user input, orchestrating tool calls, and post-processing responses — all driven by managed prompts. PromptOverrideConfiguration lets you replace any of those managed prompts with your own text, attach a custom Lambda as the parser for model outputs, or swap out the entire orchestration logic with a Lambda-based custom orchestration function. For MCP server platforms, prompt overrides are the tool for injecting platform-specific context, applying domain constraints, transforming user inputs before the model sees them, or implementing a fully custom tool-selection strategy that integrates with an external MCP tool registry.
TL;DR
Set promptOverrideConfiguration.promptConfigurations in CreateAgentCommand or UpdateAgentCommand. Each entry specifies a promptType (PRE_PROCESSING, ORCHESTRATION, POST_PROCESSING, or KNOWLEDGE_BASE_RESPONSE_GENERATION), and can override the basePromptTemplate (the prompt text using Bedrock's XML variable syntax), set inferenceConfiguration for that step, or point to a Lambda parserMode: 'OVERRIDDEN' for custom response parsing. For fully custom orchestration, set promptType: 'ORCHESTRATION' and provide a Lambda ARN in overrideLambda — Bedrock calls your Lambda each orchestration step instead of running its built-in loop. The critical gotcha: when you override the orchestration prompt, Bedrock's default $instructions$, $tools$, and $conversation_history$ placeholders must all be present in your template or the agent will not correctly receive tool schemas and conversation context.
The Bedrock Agents orchestration pipeline
Understanding the pipeline stages makes it clear where overrides apply:
| Stage | Prompt type | What happens | Override use cases |
|---|---|---|---|
| Pre-processing | PRE_PROCESSING |
Model classifies user input: is it valid? Does it need clarification? Should it be denied? | Add topic restrictions, inject user metadata, classify input intent before orchestration |
| Orchestration | ORCHESTRATION |
Model decides whether to call a tool, which tool, with what parameters, or generate a response directly | Inject platform context, modify tool selection criteria, enable custom orchestration Lambda for external tool routing |
| Post-processing | POST_PROCESSING |
Model formats the final response before returning it to the caller | Enforce response format (JSON, Markdown), add disclaimers, strip internal reasoning from output |
| Knowledge base response | KNOWLEDGE_BASE_RESPONSE_GENERATION |
Model synthesizes retrieved documents into a coherent answer | Customize citation format, emphasize recency, change synthesis style |
You can override any subset of these stages independently. Overriding one stage does not affect others. Each override is independently enabled by setting promptCreationMode: 'OVERRIDDEN' in that stage's configuration entry.
Overriding the pre-processing prompt
The pre-processing stage runs before orchestration and decides whether the user input is valid and what category it falls into. Overriding it is the safest way to add topic restrictions without touching the core orchestration prompt.
import {
BedrockAgentClient,
UpdateAgentCommand
} from "@aws-sdk/client-bedrock-agent";
const client = new BedrockAgentClient({ region: "us-east-1" });
await client.send(new UpdateAgentCommand({
agentId: "YOURAGENTID",
agentName: "platform-assistant",
agentResourceRoleArn: "arn:aws:iam::123456789012:role/BedrockAgentRole",
foundationModel: "anthropic.claude-3-5-sonnet-20241022-v2:0",
instruction: "You are a data analytics assistant.",
promptOverrideConfiguration: {
promptConfigurations: [
{
promptType: "PRE_PROCESSING",
promptCreationMode: "OVERRIDDEN",
promptState: "ENABLED",
basePromptTemplate: `You are a pre-processor for a data analytics assistant.
Analyze the user's request:
$conversation_history$
User request: $question$
Determine:
1. Is this request related to data analytics, SQL, database operations, or business intelligence? If yes, classify as VALID.
2. Is this a request to access, modify, or delete system configuration, credentials, or infrastructure? If yes, classify as INVALID with reason "Platform policy: system access requests are not permitted."
3. Is this a general question that the agent can answer from its knowledge? If yes, classify as VALID.
Respond only with XML in this exact format:
true|false
reason if false, empty if true
VALID|INVALID
`,
inferenceConfiguration: {
temperature: 0,
topP: 1,
maximumLength: 2048
}
}
]
}
}));
The pre-processing response XML format is strict — Bedrock parses the XML tags to determine whether to proceed with orchestration. The amazon:valid_input tag controls flow: true proceeds to orchestration, false returns amazon:invalid_input_reason to the caller without invoking the orchestration stage. Use pre-processing to implement platform policy guardrails without exposing the agent to the denied request.
Overriding the orchestration prompt
The orchestration prompt is the most powerful override — it controls the model's core reasoning and tool selection loop. Modify it to inject dynamic context, adjust tool selection criteria, or add platform-specific instructions that complement the static instruction field.
The orchestration template uses Bedrock's XML variable syntax. These placeholders are required in any orchestration override — omitting them breaks tool schemas injection and conversation history:
| Placeholder | What Bedrock injects | Required? |
|---|---|---|
$instructions$ |
The agent's instruction field text |
Yes — omitting loses the agent's core persona |
$tools$ |
Tool schemas for all action groups and knowledge bases | Yes — omitting means the model cannot call any tools |
$conversation_history$ |
Prior turns in the current session | Yes — omitting makes the agent amnesiac within a session |
$question$ |
The current user input | Yes — omitting means the model does not see the user's request |
$memory_content$ |
Retrieved memory summaries (if memory is enabled) | Conditional — required if memory is enabled, otherwise empty |
const orchestrationPromptOverride = `You are an AI assistant for a data platform. Use the instructions and tools below.
$instructions$
PLATFORM CONTEXT: Today is ${new Date().toISOString().split('T')[0]}. The user has read access to the reporting database and write access to their own dashboards. They do not have access to production source tables — queries against those will fail with a permission error.
TOOL SELECTION GUIDANCE:
- For SQL queries, prefer the runQuery tool over the explainQuery tool unless the user explicitly asks to understand a query.
- For dashboard operations, always confirm the dashboard name before making changes.
- For file operations, never read files outside /home/user/ and /tmp/.
$memory_content$
Available tools:
$tools$
Conversation history:
$conversation_history$
Current request: $question$`;
The platform context block above is a simple but effective pattern: inject dynamic runtime values (current date, user permissions snapshot) into every orchestration call without maintaining a separate Lambda. This keeps the orchestration personalized without the overhead of a custom orchestration Lambda.
Custom orchestration Lambda
When prompt-level overrides are insufficient — for example, when you need to implement a completely different tool selection strategy, integrate with an external tool registry like a live MCP server manifest, or implement structured reasoning that the base model does not handle well — use a custom orchestration Lambda.
Set overrideLambda in the prompt configuration for the ORCHESTRATION stage. Bedrock calls this Lambda at each orchestration step instead of its built-in orchestration loop. The Lambda receives the full orchestration context and must return either a tool call decision or a final response.
await client.send(new UpdateAgentCommand({
agentId: "YOURAGENTID",
// ... other fields
promptOverrideConfiguration: {
overrideLambda: "arn:aws:lambda:us-east-1:123456789012:function:custom-orchestrator",
promptConfigurations: [
{
promptType: "ORCHESTRATION",
promptCreationMode: "OVERRIDDEN",
promptState: "ENABLED",
// basePromptTemplate can still be provided — Bedrock passes it to your Lambda
// as the system prompt, but your Lambda controls what to do with it
basePromptTemplate: "You are a data analytics assistant. $instructions$ $tools$"
}
]
}
}));
The custom orchestration Lambda receives an event containing the orchestration context. The Lambda must return a structured response indicating the next action. The event shape at the orchestration step:
// Event received by custom orchestration Lambda
{
"messageVersion": "1.0",
"agent": {
"name": "platform-assistant",
"id": "YOURAGENTID",
"alias": "YOURALIAS",
"version": "1"
},
"inputText": "Show me last month's revenue by region",
"sessionId": "sess-abc123",
"actionGroup": "ORCHESTRATION",
"sessionAttributes": {},
"promptSessionAttributes": {},
"knowledgeBaseConfigurations": [],
"invokeModelRawResponse": {
// The raw model response from the previous orchestration step (if any)
},
"orchestrationType": "DEFAULT" // or "CUSTOM_ORCHESTRATION" after first step
}
// Lambda must return:
{
"messageVersion": "1.0",
"response": {
"actionGroup": "ORCHESTRATION",
"orchestration": {
"orchestrationState": "END_TURN", // or "CALL_TOOL"
"responseText": "Here is last month's revenue by region: ...",
// For CALL_TOOL:
// "toolUse": { "toolUseId": "uuid", "toolName": "runQuery", "content": [{...}] }
}
}
}
Custom orchestration Lambdas have full control over the tool-decision loop. They can invoke external tools directly, make their own model calls to Claude or other Bedrock models, consult an MCP server for available tools at runtime, or implement deterministic routing without using a foundation model for decisions at all.
Post-processing override
Post-processing overrides transform the orchestration output before it is returned to the caller. Use post-processing to enforce a consistent response format across all agent outputs:
const postProcessingTemplate = `You are a post-processor. Transform the agent's response into the required format.
Agent response:
$agent_answer$
User request (for context):
$question$
Format the response as:
1. If the response contains data (numbers, tables, lists): structure it clearly with appropriate headers
2. If the response is an explanation: return it as-is, cleaned of any internal reasoning markers
3. If the response is an error or refusal: format it as: { "status": "error", "message": "..." }
4. Never include phrases like "Based on the information provided" or "As an AI assistant"
5. Remove any text that starts with or
Return ONLY the formatted response, nothing else.`;
await client.send(new UpdateAgentCommand({
agentId: "YOURAGENTID",
// ...
promptOverrideConfiguration: {
promptConfigurations: [
{
promptType: "POST_PROCESSING",
promptCreationMode: "OVERRIDDEN",
promptState: "ENABLED",
basePromptTemplate: postProcessingTemplate,
inferenceConfiguration: {
temperature: 0,
maximumLength: 4096
}
}
]
}
}));
Post-processing adds a second model call to every agent response, which increases latency and cost. Only enable post-processing when the output format consistency is worth the tradeoff. For most cases, a well-crafted instruction field achieves the same formatting goals without the extra model call.
Disable post-processing explicitly if you do not need it — set promptState: 'DISABLED' in the post-processing configuration. If you have set promptOverrideConfiguration with other stage overrides, include the post-processing entry with DISABLED to ensure it is off, because the default may vary by model.
Guardrail configuration
Bedrock Guardrails are independent of prompt overrides and apply content filtering to both inputs and outputs regardless of the prompt configuration. Configure guardrails on the agent via guardrailConfiguration in CreateAgentCommand / UpdateAgentCommand:
await client.send(new UpdateAgentCommand({
agentId: "YOURAGENTID",
agentName: "platform-assistant",
agentResourceRoleArn: "arn:aws:iam::123456789012:role/BedrockAgentRole",
foundationModel: "anthropic.claude-3-5-sonnet-20241022-v2:0",
instruction: "You are a data analytics assistant.",
guardrailConfiguration: {
guardrailIdentifier: "arn:aws:bedrock:us-east-1:123456789012:guardrail/abc123def456",
guardrailVersion: "1"
}
}));
Guardrails operate at the Bedrock service layer — they intercept model inputs and outputs before the agent's prompt override logic runs. This means a guardrail block on input prevents the pre-processing Lambda from even seeing the content. Guardrail blocks on output prevent post-processing from receiving blocked content. For MCP server platforms, this layering means:
- Use guardrails for universal, compliance-driven content filtering (PII detection, profanity, topic denial) that must apply regardless of agent configuration.
- Use pre-processing prompt overrides for domain-specific, context-aware input validation that requires the model to reason about the input.
- Use post-processing prompt overrides for output formatting and style normalization.
Guardrails also support word filters, sensitive information filters, grounding checks (for RAG), and contextual grounding that checks whether the model's response is grounded in retrieved documents. Configure these in the Bedrock console or via CreateGuardrailCommand before referencing the guardrail ARN in the agent configuration.
Combining overrides with memory
When both memory and orchestration prompt override are enabled, the $memory_content$ placeholder must be in your orchestration template. Without it, stored session summaries are not injected into the context — memory is configured and summaries are generated, but they never reach the model.
// Minimal orchestration template that works with memory enabled
const orchestrationWithMemory = `$instructions$
$memory_content$
$tools$
$conversation_history$
$question$`;
Bedrock substitutes $memory_content$ with an XML block containing the retrieved session summaries. For the first session of a new user (no stored memories yet), $memory_content$ is substituted with an empty string — no special handling needed in your template.
Prompt override change management
Changing a prompt override requires re-preparing the agent and publishing a new version. For production systems, follow a staged rollout:
- Update the
DRAFTversion with the new prompt override configuration. - Call
PrepareAgentCommandto compile the new configuration. - Test the
DRAFTversion via aDRAFTalias before publishing. - Call
CreateAgentVersionCommandto snapshot the currentDRAFTinto a numbered version. - Update a staging alias to point to the new version.
- Run integration tests or shadow traffic against staging.
- Update the production alias to the new version — this is instant with no downtime.
// Point an alias at the new version
await client.send(new UpdateAgentAliasCommand({
agentId: "YOURAGENTID",
agentAliasId: "YOURAGENTALIASID",
agentAliasName: "prod",
routingConfiguration: [
{ agentVersion: "5" } // Switch from version 4 to version 5
]
}));
// Rollback by switching the alias back
await client.send(new UpdateAgentAliasCommand({
agentId: "YOURAGENTID",
agentAliasId: "YOURAGENTALIASID",
agentAliasName: "prod",
routingConfiguration: [
{ agentVersion: "4" } // Instant rollback
]
}));
Alias routing configuration also supports A/B testing by specifying multiple versions with traffic percentages. Use this to gradually roll out a prompt change — route 10% of traffic to the new version, monitor quality via CloudWatch metrics on invocation errors and human feedback signals, then increase the percentage as confidence grows.