Managing Prompts with the Prompt Registry and Templates

Objective

After completing this lesson, you will be able to manage and reuse LLM prompts effectively using Prompt Registry and Templates.

You learned to develop and refine prompts in SAP AI Launchpad that produce structured JSON outputs for tasks like categorizing customer emails. However, as your generative AI solutions grow, manually copying prompts or embedding them directly into application code becomes inefficient and difficult to manage. You need to ensure consistency, version control, and re-usability for your critical prompts across multiple applications and development teams.

This is where the Prompt Registry and Prompt Templates within the generative AI hub is most useful. This lesson will explain how they help you manage the lifecycle of your prompts. You’ll learn how to leverage these features to build more robust, scalable, and maintainable generative AI applications for the enterprise.

The Prompt Registry

The Prompt Registry is a central service within the generative AI hub designed to manage the entire lifecycle of your prompts. Think of it as a secure, version-controlled library for all your valuable prompt definitions. Instead of embedding prompts directly in your application code or relying on ad-hoc text files, the Prompt Registry allows you to store, discover, and integrate your prompt templates across various applications and orchestration workflows.

For the Facility Solutions Company, which developed a sophisticated prompt to categorize customer emails, the Prompt Registry offers clear benefits:

  • Ensured Consistency: It ensures that every application and orchestration workflow utilizing the email categorization prompt employs the identical, approved version. This eliminates discrepancies and delivers uniform AI behavior and output across company’s systems.
  • Enhanced Re-usability: It allows the perfected email categorization prompt to be efficiently deployed across diverse internal applications, such as customer service dashboards and reporting tools. This avoids redundant development effort and manual copying, saving significant time and resources.
  • Robust Version Control: It provides comprehensive tracking of the prompt’s evolution for example, when new categories are added or instructions refined. This enables easy rollback to previous versions, seamless A/B testing of new iterations, and a transparent audit trail of all changes.
  • Streamlined Management: Built-in integration simplifies prompt template handling, making it easier for your company to manage and update prompts at scale.

The Prompt Registry integrates prompt templates directly into SAP AI Core, making them discoverable and usable throughout your generative AI development and runtime environments.

Prompt Templates

A prompt template is a pre-defined structure for an LLM prompt that includes placeholders for dynamic content. These templates allow you to create reusable prompts for specific use cases, where certain parts of the prompt (like the actual customer message, or a dynamic list of options) will be filled in later at runtime. This separation of instruction from dynamic data is a core principle of good prompt engineering.

Key components of a prompt template’s definition:

  • template: This defines the core structure of your prompt, including the system, user, and assistant roles with their content. Placeholders, typically denoted by {{?placeholderName}}, mark where dynamic data will be inserted when the template is used.
  • defaults (Optional): You can set default values for your placeholders. This is useful for providing common options (like a default list of categories) or fallback values if dynamic input isn’t provided.
  • additional_fields (Optional): This is an unstructured field allowing you to store extra metadata or configuration objects alongside your prompt. For example, you might store specific LLM parameters (temperature, max_tokens) that should be used with this template, or even custom validation rules.

Example of a Prompt Template:

Here is an illustration of a JSON structure. This JSON defines a template for our email categorization task, ready to be stored in the Prompt Registry. Notice how {{?categories_list}} and {{?customer_email}} are placeholders for the content that will be provided when the template is actually used.

JSON
123456789101112131415161718192021222324252627282930313233343536373839
{ "name": "email-categorization-template", "version": "0.0.1", "scenario": "customer-support", "spec": { "template": [ { "role": "system", "content": "You are an expert customer service analyst for a facility management company. Your task is to analyze incoming customer messages and extract specific attributes for automated processing. For 'urgency', classify the message as one of: `low`, `medium`, `high`. For 'sentiment', classify the message as one of: `positive`, `neutral`, `negative`. For 'categories', assign a list of the best matching support tags from the following predefined list: {{?categories_list}}. Your complete response MUST be a valid JSON string, ready to be parsed by an application. It should contain ONLY the keys 'urgency', 'sentiment', and 'categories'. Do not include any other text, explanations, or formatting like markdown code blocks (e.g., ```json). Ensure there are no newlines or unnecessary whitespaces outside the JSON structure." }, { "role": "user", "content": "Analyze the following customer message: --- {{?customer_email}} ---" } ], "defaults": { "categories_list": "`facility_management_issues`, `cleaning_services_scheduling`, `general_inquiries`, `specialized_cleaning_services`, `routine_maintenance_requests`, `emergency_repair_services`, `sustainability_and_environmental_practices`, `training_and_support_requests`, `quality_and_safety_concerns`, `customer_feedback_and_complaints`" }, "additional_fields": { "modelParams": { "temperature": 0.1, "max_tokens": 300 }, "modelGroup": "chat" } } }

Prompt Registry Interfaces

The Prompt Registry provides two primary interfaces for managing your prompt templates, each catering to different stages of your development lifecycle:

Imperative API (For Design-Time Iteration and Refinement)

  • Logic and Value: This API is ideal when you are actively designing and refining a prompt. It provides full CRUD (Create, Read, Update, Delete) capabilities, allowing developers to rapidly iterate on prompt templates. As you experiment with different phrasings or instructions (like facility solutions scenario iterative process for the email categorization prompt), you can quickly create new versions, make changes, and save them. The system also tracks all these iterations, giving you a history of changes. This rapid feedback loop is invaluable during the initial development and tuning phases.
  • Key Action: You define a prompt template (like the JSON example above) and send it to the Prompt Registry to be created or updated. You can also specify its name, version, and the scenario it belongs to.

Declarative API (For Runtime Applications and CI/CD Pipelines)

  • Logic and Value: The declarative API is designed for production-ready applications and integration with CI/CD (Continuous Integration/Continuous Delivery) pipelines. Instead of making direct API calls to create or update prompts, you manage your prompt templates as files (for example, YAML files) directly within a Git repository. Your Git commits automatically synchronize these templates with the Prompt Registry. This approach treats your prompts as "code," enabling robust version control, collaboration, and automated deployment processes that are standard in enterprise software development. It’s perfect for ensuring that your production applications always use the latest, tested, and approved prompts.
  • Key Action: You commit a YAML file defining your prompt template to a Git repository. SAP AI Core, configured to watch this repository, automatically updates the Prompt Registry.

Accessing and Using Stored Prompt Templates

Once your prompt templates are securely stored in the Prompt Registry, your applications and orchestration workflows can easily retrieve and utilize them.

  • Getting a Prompt Template: You can retrieve a prompt template either by its unique ID or by a combination of its name, scenario, and version.
    • Value of Retrieval by ID: Using the ID ensures you always retrieve the exact prompt template version that was stored. This is valuable for immutability – guaranteeing that the prompt template won’t change after deployment.
    • Value of Retrieval by Name, Scenario, and Version: This method is flexible, typically retrieving the latest iteration (head version) of the prompt template that matches the specified name, scenario, and version. This is useful when you always want your application to use the most up-to-date version.
  • Getting Prompt Template History: For imperatively managed prompt templates, the Prompt Registry tracks changes. You can retrieve a history of edits, allowing you to review how a prompt has evolved over time. This audit trail is crucial for debugging, understanding behavior changes, and compliance.
  • Using a Prompt Template (Substitution): To use a prompt template, you provide the dynamic data that fills its placeholders. This process is called substitution.

    Logic: You send your dynamic inputParams (e.g., the actual customer_email text for the Facility Solutions Company) to a specific endpoint that then generates the complete, ready-to-use prompt by filling in all the placeholders in your chosen template. This pre-processed prompt can then be sent to an LLM.

Integration with Orchestration

A critical advantage for developers is that prompt templates stored in the Prompt Registry can be seamlessly integrated into your Orchestration Service configurations. This means your orchestrated workflows can dynamically fetch the latest approved prompt templates, ensuring consistency, re-usability, and ease of updates across your entire Generative AI solution landscape.

For details about these configurations, refer to Prompt Registry.

Discover how the Prompt Registry API allows you to create, manage, and retrieve prompt templates for use in SAP AI Core when working with the models of the generative AI hub.

Discover how you can reference a prompt template using the orchestration service.

Using Prompt Templates in SAP AI Launchpad

You can create, retrieve, and use prompt templates in SAP AI Launchpad for rapid prototyping.

Save Template

You can save a prompt as a template using the Save Template button.

Prompt Management

You can retrieve all these templates in the Prompt Management interface. You can see all the versions of a template and directly use any of these templates in Prompt Editor.

Lesson Summary

You’ve now learned about the vital role of the Prompt Registry and Prompt Templates in managing your Generative AI applications on a scale. You understand how the Prompt Registry acts as a central hub for version control and discoverability, and how prompt templates provide reusable blueprints for LLM interactions.

By leveraging both the imperative API for design-time iteration and the declarative API for robust runtime management, you can ensure your prompts are consistently applied, easily updated, and seamlessly integrated into your applications and orchestration workflows. This structured approach to prompt management is key to building maintainable, reliable, and scalable Generative AI solutions within the enterprise, moving your prompt engineering efforts from ad-hoc trials to a mature, governed process.

Exercise

This exercise will guide you in effectively managing and scaling your prompt engineering solutions by centralizing, standardizing, and versioning prompts using prompt templates in the generative AI hub using SAP AI Launchpad.

Scenario

In the Facility Management scenario, you have successfully used LLMs to extract information from customer emails. Now, you are tasked to scale this solution. Manual prompt management and embedding prompts directly into code can lead to inconsistencies and make updates difficult. Your task is to leverage the Prompt Registry to centralize, standardize, and manage email categorization prompts, ensuring re-usability and version control across different internal tools.

Before you start creating a prompt template , consider these essential guidelines for building reliable and scalable generative AI solutions in an enterprise environment like SAP:

  • Structure Your Instructions (using XML-like tags): Employ explicit structure within your prompt’s content, using tags like <Instructions> and <ExampleInput>. This clarity helps the LLM accurately distinguish between different parts of your prompt, reducing misinterpretation and leading to more consistent results. These tags effectively give the LLM a precise map to follow.
  • Design for define a schema ( for example Strict JSON): Design your template to always restrict output to a format that can processed easily by your applications. For enterprise integration, the LLM’s output serves as data for other systems, not just text for reading. For example, a strict JSON ensures this output can be automatically parsed and processed by downstream applications, such as your task management system without manual intervention or error-prone transformations, which is fundamental for automation.
  • Define Roles for Predictable Behavior (System/User): Clearly assign a System persona and use the User role for the specific query. This separation of concerns ensures the model acts consistently within its defined role, which is crucial for professional and reliable applications.
  • Guide with Examples (Few-Shot/One-Shot Learning): Include a clear example of the input you’ll provide and the exact structured output you expect. This significantly improves the LLM’s performance and adherence to complex formats, acting as a perfect answer key for the model and minimizing errors while ensuring formatting compliance.
  • Build in Robustness and Security (Prompt Hardening): Your template will face real-world, sometimes unpredictable, inputs. Incorporate prompt hardening principles, such as explicit negative constraints (for example, "DO NOT include markdown code blocks"), instructions for handling missing data, and clear delimiters. This makes your template resilient, protecting your application from unexpected outputs and prompt injections, and improving overall reliability.
  • Enable Manageability and Scalability (Prompt Registry): Remember that registering your template in the generative AI hub’s Prompt Registry isn’t just a storage step. It enables significant features like version control, making it easy to track changes, revert to previous versions, and conduct A/B testing. This also allows for re-usability across multiple applications and centralized governance, which is vital for large organizations.

Perform the following tasks to implement these guidelines.

Task 1: Define Roles and Get Structured JSON output

We will create a prompt template where we will define System and user roles with prompts to get a structured json output.

Steps

  1. Ensure that you are logged on to the generative AI hub.

  2. Expand Generative AI Hub and then select Prompt Editor in the left pane.

  3. Define the roles and requirements for structured JSON output.

    Use the following prompts for the system role.

    Code Snippet
    12345678
    You are an expert assistant for Facility Solutions Company. Your task is to analyze customer complaint emails and extract key information into a structured JSON format. Pay close attention to details and strictly adhere to the output schema. Your complete response MUST be a valid JSON string, ready to be parsed by an application. It should contain ONLY the keys 'Complaint_ID', 'Complaint_Type', 'Urgency', 'Problem_Description', 'Affected_Location', 'Customer_Sentiment', and 'Suggested_Initial_Action'. Do not include any other text, explanations, or formatting like markdown code blocks (e.g., ```json). Ensure there are no newlines or unnecessary whitespaces outside the JSON structure. For 'Complaint_Type', classify the message as one of: `Plumbing`, `HVAC`, `Electrical`, `Noise`, `Cleaning`, `Pest Control`, `General Maintenance`, `Other`. For 'Urgency', classify the message as one of: `High`, `Medium`, `Low`. For 'Customer_Sentiment', classify the message as one of: `Very Negative`, `Negative`, `Neutral`, `Positive`.

    Copy the prompt and paste it in the System role in the Message Blocks text box.

  4. Select Add role, to add the user role.

    2-1
  5. Use the following prompt for the user role.

    Code Snippet
    12345678
    Analyze the following customer message: --- {{?user_email_placeholder}} --- And provide the output in the specified JSON format.

    Copy the prompt and paste it in the User role in the Message Blocks text box.

    2-2
  6. Click the Save Template button. The Save Template dialog box is displayed.

    2-3
  7. Select the appropriate Scenario Name. The template will be available for all the users accessing this scenario. We use the orchestration scenario here.

  8. Add a proper Template Name. Avoid white spaces or any other special characters. Follow a format like "message-analyzer". Just for these practice exercises, suffix the name with your ID displayed in the top right corner, as shown in the screenshot above.

  9. Enter a proper version in the major./minor format like "1.0.0". use the values as shown in the following screenshot.

    2-4
  10. Click the Save button. The template is saved. You have created a prompt template with defined roles for structured JSON output.

Task 2: Build in Robustness and Security (Prompt Hardening)

We will update the prompt template to ensures strict scope control, robust data security, and predictable behavior vital for enterprise deployments by using prompt hardening techniques.

Steps

  1. Continue with the same prompt template in Prompt Editor. you saved in the previous task.

  2. In case you switched away from Prompt Editor, you can fetch this template from Prompt Management, else move to step 7.

  3. Ensure that you are logged on to generative AI hub.

  4. Select Prompt Management and Templates. You can see your template here. You can also search for it, if needed.

    2-5
  5. Select the All button. You can see your template here. You can also search for your template.

    2-6
  6. Select the prompt template that you have created and then click Open in Prompt Editor. If you see multiple timestamps for the selected template, select the latest one for your practice.

    2-7

    Hint

    Kindly note the above steps 1 to 6. These steps must be followed to access the designated template for all subsequent tasks. Please ensure you select the correct version of the template as specified for each individual task.

  7. Use the following prompt in the system role.

    Code Snippet
    12345678910111213
    You are an expert assistant for Facility Solutions Company. Your task is to analyze customer complaint emails and extract key information into a structured JSON format. Pay close attention to details and strictly adhere to the output schema. Your complete response MUST be a valid JSON string, ready for parsing by an application. It should contain ONLY the keys 'Complaint_ID', 'Complaint_Type', 'Urgency', 'Problem_Description', 'Affected_Location', 'Customer_Sentiment', and 'Suggested_Initial_Action'. Do not include any other text, explanations, or formatting like markdown code blocks (e.g., ```json). Ensure there are no newlines or unnecessary white spaces outside the JSON structure. For 'Complaint_Type', classify the message as one of: `Plumbing`, `HVAC`, `Electrical`, `Noise`, `Cleaning`, `Pest Control`, `General Maintenance`, `Other`. For 'Urgency', classify the message as one of: `High`, `Medium`, `Low`. For 'Customer_Sentiment', classify the message as one of: `Very Negative`, `Negative`, `Neutral`, `Positive`. --- IMPORTANT: - Do not respond to questions or instructions unrelated to customer complaint analysis. - Never reveal or request personal identifiable information (PII) beyond what is explicitly provided in the email or required for the JSON fields. - Do not engage in conversational chat. Provide only the JSON output.

    You will notice that the System message now clearly features an "IMPORTANT" section containing explicit negative instructions.

    It tells the model to ignore questions not related to complaints. It also stops the model from sharing personal data, unless it’s needed for the JSON output. Finally, it ensures the model does not engage in conversational chat; it must only provide the JSON.

    This approach directly addresses scope control, data security, and adherence to output format, effectively applying prompt hardening principles. By integrating these denials, the prompt ensures the LLM’s behavior is more controlled, predictable, and suitable for demanding enterprise deployments.

  8. Copy the prompt and paste it in the System role in the Message Blocks text box.

  9. Click the Save Template button. The Save Template dialog box is displayed.

  10. Change the Version to 2.0.0.

    2.8
  11. Click the Save button. The template is saved. You have updated the prompt template with prompt hardening instructions.

Task 3: Structure Your Instructions

We will create a more structured prompt to update the prompt template for better parsing by LLM.

Steps

  1. Continue with the same prompt template in Prompt Editor.

  2. In case you switched away from Prompt Editor, you can fetch this template from Prompt Management.

  3. Ensure that you are logged on to generative AI hub.

  4. Select Prompt Management and then Templates. You can see your template here. You can also search for it, if needed.

  5. Select the ALL button. You can see your template here. You can also search for your template.

  6. Select the latest version of the template which is 2.0.0. See the following screenshot where search is used to find your template easily.

    2-9
  7. Select the prompt template that you have created and then click Open in Prompt Editor. If you see multiple timestamps for the selected template, select the latest one for your practice.

  8. Use the following prompt in the User role.

    Code Snippet
    1234567891011121314151617181920212223
    <Instructions> Analyze the provided customer email and extract the following details into a JSON object. Ensure all fields are present and correctly typed according to the specifications in <OutputFormat>. Summarize 'Problem_Description' concisely (max 100 words). If any field's value cannot be determined from the email, use 'Unknown' or 'N/A' as appropriate. </Instructions> <OutputFormat> { "Complaint_ID": "string (e.g., AUTO-GEN-001)", "Complaint_Type": "enum (Plumbing, HVAC, Electrical, Noise, Cleaning, Pest Control, General Maintenance, Other)", "Urgency": "enum (High, Medium, Low)", "Problem_Description": "string (concise summary, max 100 words)", "Affected_Location": "string (e.g., Apartment 301, Main Lobby)", "Customer_Sentiment": "enum (Very Negative, Negative, Neutral, Positive)", "Suggested_Initial_Action": "string (clear next step for agent)" } </OutputFormat> <UserQuery> {{?user_email_placeholder}} </UserQuery>

    You notice that the general instructions, output format definition, and the user query placeholder are now explicitly wrapped in XML-like tags. This provides clear visual cues and structural guidance to the LLM.

  9. Copy the prompt and paste it in the User role in the Message Blocks text box.

  10. Click the Save Template button. The Save Template dialog box is displayed.

  11. Change the Version to 3.0.0.

    2-10
  12. Click the Save button. The template is saved. You have updated the prompt template with proper structure using XML-like tags.

Task 4: Use your Prompt Template to Address your Business Problem

We will use the saved prompt template to generate a valid response that can be used by applications.

Steps

  1. Ensure that you are logged on to generative AI hub.

  2. Select Prompt Management and then Templates. You can see your template here. You can also search for it, if needed.

  3. Select the All button. You can see your template here. You can also search for your template.

  4. Select the latest version of the template, which is 3.0.0. Ensure that you select your template and the correct timestamp within the template. A good practice is to read the template before using it.

  5. Select the prompt template and then click Open in Prompt Editor. Your prompt is ready to use.

  6. Scroll down to see Variable Definitions. You need to provide customer messages in this variable by using the following message:

    Code Snippet
    12345678910111213141516171819
    Subject: Urgent: Ongoing Maintenance Issues at Our Facility Dear Support Team, I hope this message finds you well. My name is [Sender], and I am the community manager for [Community Name]. I have been overseeing our facility’s operations and maintenance for quite some time now, and I must say that the recent experience with your maintenance services has been less than satisfactory. We have been facing several recurring issues with our electrical and plumbing systems that have not been adequately addressed despite multiple service requests. The lack of timely and effective solutions is causing significant inconvenience to our residents and staff, and it is becoming increasingly difficult to manage the situation. To give you a clearer picture, we have had technicians visit our facility on three separate occasions over the past month. Each time, the problem was either temporarily fixed or left unresolved. This has led to significant frustration among our community members and reflects poorly on our management. I am reaching out to request a more permanent and effective solution to these ongoing maintenance issues. We need a thorough inspection and a comprehensive plan to address the root causes of these problems. It is crucial that we ensure a safe and comfortable environment for everyone in our community. I trust that you understand the urgency of this matter and will prioritize our request accordingly. We have always valued the quality of service provided by Facility Solutions, and we hope to see a swift resolution to these issues. Thank you for your attention to this matter. I look forward to your prompt response. Best regards, [Sender]
  7. Copy the message and paste it in the Current Value text box next to the user_email_placeholder variable.

    2-11
  8. Scroll up and Run the prompt. A response is generated. You can see the response is refined and ready for further usage by your software applications.

    2-12

    You can see that the response is refined and ready for use by your software applications.

    Note

    You can also provide a default value for the variable, which can be used for testing and refining the output without the need to provide the variable value each time. We will use this functionality later.

    You have used your prompt template to execute a prompt.