PM-301a · Module 2

Context Injection Patterns

4 min read

Context injection is the pattern of inserting runtime data into the system prompt at request time. The system prompt template contains placeholders; the application fills them before sending the request to the model. This keeps static instructions separate from dynamic data and enables multi-tenant deployments without duplicating prompt logic.

## CONTEXT [injected at runtime]
Current date: {{CURRENT_DATE}}
User: {{USER_NAME}} ({{USER_ROLE}})
Organization: {{ORG_NAME}}
Subscription tier: {{SUBSCRIPTION_TIER}}
Available tools: {{TOOL_LIST}}

## ROLE
You are a support specialist for {{ORG_NAME}}.
Address the user as {{USER_NAME}}.
{{USER_ROLE === 'admin' ? 'You may discuss billing and account management.' :
  'For billing questions, direct the user to their account administrator.'}}

## BEHAVIOR
[static instructions that do not change per user]
  1. User Metadata Name, role, subscription tier, permissions. Enables personalized behavior without separate system prompts per user. Critical: validate this data server-side before injection. Never trust user-supplied metadata injected directly into the system prompt.
  2. Org Context Organization name, industry, product lines, known preferences. Allows one base prompt to serve multiple clients. The model's responses are contextually appropriate without requiring the user to re-explain their context every session.
  3. Tool Availability List the tools available in this session. Prevents the model from hallucinating tool calls to tools that are not connected, and from failing to use tools that are available. Inject tool names and one-line descriptions, not full schemas — those are in the API call.
  4. Date and Time Always inject the current date. Models have a knowledge cutoff and do not know "today" without being told. Missing date context causes incorrect relative-time reasoning: "recently," "this year," "upcoming" all become unreliable.