Skip to main content

Prompt Template Overview

When building large language model (LLM) applications, repeatedly constructing and fine-tuning structurally similar Prompts across different business scenarios is time-consuming and difficult to maintain. By using Prompt templates, you can separate fixed template structure from dynamic variables—enabling reusable, centrally managed, and optimized Prompt generation.

Workflow

  1. Create a template: Create and save a template via the Alibaba Cloud Bailian console or API, obtaining a unique template ID.
  2. Retrieve the template: Fetch the template content using the API and its template ID.
  3. Generate a Prompt: Populate template variables with business data to produce the final Prompt.
  4. Use the template: Send the generated Prompt to the target LLM to obtain results.

Template Types

Prompt templates fall into two categories: predefined templates and custom templates.
DimensionPredefined Prompt TemplatesCustom Prompt Templates
SourceProvided by Alibaba Cloud Bailian, covering multiple common business scenarios.Created by users via console or API.
EffectivenessOptimized and stable in performance.Effectiveness depends on user design quality; requires iterative testing and tuning.
Ease of UseNo additional development required—ready for immediate use via console or API.May require multiple iterations. Users must understand Prompt engineering principles and optimization techniques (e.g., clear instructions, few-shot examples, format constraints) and possess basic development/technical skills.
Applicable ScenariosGeneral-purpose use cases, e.g., creative copywriting, office assistants.
Recommended for users with limited Prompt design experience.
Complex or domain-specific needs, e.g., financial risk control, medical consultation.
Required when strict output formatting is needed (e.g., JSON, lists).
ModifiabilityNot editable.Fully customizable per business requirements.

Predefined Prompt Templates

Viewing

Predefined Prompt templates are currently viewed mainly through the API: call ListPromptTemplates with type=System to retrieve all predefined templates available in the current workspace, along with their variables. The console's Prompt Management page (in the left navigation, choose Tools > Prompt Management) mainly displays custom templates; the card view for predefined templates may vary by console version. When shown as cards, each card displays a summary of its content and its template ID, with buttons: View Details, Copy, and more actions (...).

Viewing & Managing

  • View: Click View Details on a template card to open a side drawer showing the template's name, category, content, variables, template ID, and API information (code examples).
  • Copy template content: Click Copy to copy the full template content.
  • Create an application: Click More icon (···), then select Create Application to auto-populate the prompt editor with the template. You may use it as-is or adapt it to your business context. The pre-filled prompt includes custom variables like ${number} and ${content}, designed for generating Xiaohongshu-style copy.
  • Copy to custom template: Click More icon (···), then select Copy Template, or click Copy to Custom Template in the details drawer, to create a custom template named "[Original Template Name]_Copy_[Timestamp]" on the Prompt Management page.
  • Code example: In the API information area of the details drawer, view core SDK usage code. Note: This is a minimal working snippet—not executable standalone. For complete, runnable examples, refer to the SDK section under GetPromptTemplate – Retrieve a Prompt Template.

Custom Prompt Templates

Creation

You can create custom Prompt templates either via the console or API. Console
  • Based on a predefined template: On any predefined template card, click More icon (···), then select Copy Template, or click Copy to Custom Template in the details drawer, to generate a custom copy named "[Predefined Template Name]_Copy_[Timestamp]".
  • From scratch: On the Prompt Management page, click Create Prompt in the top-right corner, complete the configuration, and save the template. On the Prompt Template Management page, filter templates by type (All, Text Generation, Image Generation) or search by keyword. Created templates appear as cards showing title, content preview, and template ID—and support Edit and Copy.
API
  • Obtain your workspace ID: see Get workspace ID.
  • Create a custom template: use the CreatePromptTemplate operation.

Viewing & Managing

  • View: After creation, custom templates appear on the Prompt Management page.
  • Manage:
    • Click Edit on a template card to modify its content.
    • Click Copy to copy the full template content.
    • Click More icon (···), then select Create Application to auto-populate the prompt editor. Use as-is or adapt further.
    • Click View Details to view core SDK usage code in the side drawer. Note: This is a minimal working snippet—not executable standalone. For complete, runnable examples, refer to the SDK section under GetPromptTemplate – Retrieve a Prompt Template.
    • Click More icon (···), then select Copy Template to create a new custom template named "[Custom Template Name]_Copy_[Timestamp]".
    • Click More icon (···), then select Delete to remove the template permanently.

Using Prompt Templates

Console

Click More icon (···), then select Create Application on any predefined or custom template card to auto-fill its content into the agent application's system prompt field. The filled-in prompt input box shows template variables (e.g., ${name}). A character counter appears at the bottom-right corner—maximum supported length is 6,144 characters. Configure your application's model and test the prompt by entering a sample question. In the model debugging interface, select a model (e.g., Qwen-Plus-Latest 128K) on the left and write your system instruction in the prompt area; enter a test query in the user input field on the right and click Run. Model response, along with token count statistics (input/output), appears below.

API

  1. Open the GetPromptTemplate API reference, then click Try It Out.
  2. Enter your workspaceId and promptTemplateId in the corresponding fields:
    • workspaceId: Your business workspace ID. See Get workspace ID.
    • promptTemplateId: The ID of either a predefined or custom template—found directly on its template card.
  3. Click Send Request to invoke and debug the API online.
Successful call example:
{
  "variables": ["platform", "topic", "num1", "num2"],
  "promptTemplateId": "cfec40c311f14f3e976403059d8f0116",
  "requestId": "8C616xxx",
  "name": "Marketing Copy Generator",
  "content": "You are a professional viral marketing copywriter experienced on the ${platform} platform. Now, craft compelling marketing content centered around \"${topic}\". Requirements: (1) An SEO-optimized, attention-grabbing headline; (2) A detailed, emotionally engaging body paragraph. Within the body, include at least ${num1} distinct emoji symbols to boost interactivity and visual appeal. Also, suggest up to ${num2} trending hashtags highly relevant to the topic and appealing to the target audience."
}

SDK

  1. Open the GetPromptTemplate API reference, then click Try It Out.
  2. Enter your workspaceId and promptTemplateId. Upon configuration, these values auto-populate in the SDK code samples.
    • workspaceId: Your business workspace ID. See Get workspace ID.
    • promptTemplateId: The ID of either a predefined or custom template—found directly on its template card.
  3. Click SDK Examples, then choose to:
    • Run the example online, or
    • Download the full project, configure accessKeyId and accessKeySecret, and run locally. See Create an AccessKey pair for setup instructions.
  4. On the OpenAPI debugging page, click the SDK Examples tab on the right. Select SDK Version 2.0 (Recommended) and your preferred language (e.g., Java) to view the corresponding SDK code.

Production Deployment Best Practices

Cache template content: The response from GetPromptTemplate (i.e., the template content) remains unchanged unless the template is modified. We recommend caching this content at your application layer using templateId as the cache key. This significantly reduces redundant API calls, lowering latency and cost. When updating a template, manually invalidate—or programmatically expire—the associated cache entry.

Sample Outputs

  • Description:Quickly generates eye-catching titles for various traffic channels.
  • Recommended scenarios:Marketing & Promotion
  • Template content:You are a professional Xiaohongshu viral title expert. Generate 10 attention-grabbing titles about "Hangzhou Asian Games", incorporating keywords "YYDS", "Save for Later", and "Behind-the-Scenes". Each title must be ≤20 Chinese characters.
  • Generated output:
    • 【YYDS】Behind-the-Scenes of Hangzhou Asian Games!
    • 【Save for Later】Unmissable Highlights from Hangzhou Asian Games!
    • Hangzhou Asian Games 【YYDS】Exclusive Interview with Gold Medalists!
    • 【Behind-the-Scenes】Full Reveal of Hangzhou Asian Games Venues!
    • Hangzhou Asian Games 【YYDS】Gold Medal Event Recap!
    • 【Save for Later】Touching Stories of Hangzhou Asian Games Volunteers!
    • Hangzhou Asian Games 【YYDS】Exclusive Insights from Gold Medal Coaches!
    • 【Behind-the-Scenes】Food Exploration Tour at Hangzhou Asian Games!
    • Hangzhou Asian Games 【YYDS】Golden Moments Recap!
  • Description:One-click generation of high-quality promotional copy for diverse channels.
  • Recommended scenarios:Marketing & Promotion
  • Template content:You are a professional Xiaohongshu viral marketing copy expert. Write promotional content about "Smart Bluetooth Headphones", including a title and body text, plus trending hashtag suggestions.
  • Generated output:
    • Title: Smart Bluetooth Headphones: Your New Music Companion
    • Body: Tired of tangled cables? Craving music freedom anytime, anywhere? Meet our smart Bluetooth headphones!
    • Equipped with cutting-edge Bluetooth 5.0, they deliver rock-solid connectivity and crystal-clear audio—perfect for music, movies, or gaming.
    • Touch controls let you skip tracks or answer calls with a tap.
    • Battery lasts up to 8 hours per charge—ideal for all-day use.
    • Available in sleek monochrome or vibrant colors—there's a style for every personality.
    • Order now—limited-time discount applies!
    • Trending Hashtags: #SmartBluetoothHeadphones #WirelessAudio #TouchControl #LongBatteryLife #ColorfulOptions
  • Description:Rapidly creates high-conversion product "recommendation" copy.
  • Recommended scenarios:Marketing & Promotion, E-commerce
  • Template content:You're an experienced Xiaohongshu product reviewer. Write a Xiaohongshu-style review for "Negative-Ion Hair Dryer", covering appearance, performance, benefits, and competitive advantages to drive purchase intent.
  • Generated output:
    • Title: Negative-Ion Hair Dryer: Revive Your Hair's Natural Shine!
    • Body: Still battling frizzy, dull, split ends? Try this negative-ion hair dryer!
    • Its advanced negative-ion tech neutralizes static, leaving hair smoother and shinier.
    • Adjustable heat settings suit quick-drying or gentle styling.
    • Sleek, minimalist design fits beautifully in any bathroom or bedroom.
    • Grab yours today—special offer active!
    • Trending Hashtags: #NegativeIonHairDryer #HairCare #AdjustableHeat #SleekDesign #LimitedOffer
  • Description:Efficient summarization tool for office and learning contexts.
  • Recommended scenarios:Productivity Tools, Learning Aids
  • Template content:You're a professional article summarizer. Generate a concise summary (<200 chars) of the following text: ["Green" is one of the core concepts behind the Hangzhou Asian Games; "Zero-Waste Asian Games" embodies this green principle...]
  • Generated output:
    • The Hangzhou Asian Games embraces "green" principles, notably through its pioneering "Zero-Waste Asian Games" initiative—reducing solid waste via lifecycle management. Over 33 venues, 81 hotels, and 4 factories have been certified. Construction prioritized renovation over new builds, adopted prefabricated structures and recyclable materials, cut steel use by ~1/3, and deployed solar lighting saving 30% energy annually. Food waste was minimized via centralized prep and "Cloud Asian Games Village" low-carbon accounts rewarding eco-actions.
  • Description:Refines input text per specified stylistic requirements.
  • Recommended scenarios:Productivity Tools, Learning Aids
  • Template content:You're a professional copy editor. Polish this text: "The weather today is absolutely wonderful—I saw a kitten playing among flowers on my way to school. It looked so happy. After school, I shared this fun moment with Mom." Apply modern diction and rhetorical devices to make it more concise and engaging.
  • Generated output:
    • Original: The weather today is absolutely wonderful—I saw a kitten playing among flowers on my way to school. It looked so happy. After school, I shared this fun moment with Mom.
    • Polished: What a glorious day! On my way to school, I spotted a kitten frolicking among blossoms—pure joy in motion. Back home, I couldn't wait to tell Mom all about it!
  • Description:Rewrites input text in multiple specified styles.
  • Recommended scenarios:Productivity Tools, Learning Aids
  • Template content:You're a professional style-rewriting expert. Rewrite this text in 3 distinct Xiaohongshu styles—each uplifting and positive: "Life feels monotonous—same routine, same commute, same desk. Yet this rhythm is common in modern society, driven by livelihood or career demands."
  • Generated output:
    • Xiaohongshu Style 1: Monotony? Nah—it's your canvas. Shift perspective: try something new daily. Challenge yourself. Surprise yourself. Positivity transforms routine into ritual.
    • Xiaohongshu Style 2: Same path? Same pace? That's okay—you own the upgrade. Rise earlier for yoga. Learn coding. Book that weekend getaway. Small shifts spark big joy.
    • Xiaohongshu Style 3: Repetition isn't emptiness—it's fertile ground. Practice gratitude. Savor micro-moments. Lend a hand. Joy blooms where intention meets action.
  • Description:Extends input text into longer narratives (e.g., stories, articles).
  • Recommended scenarios:Productivity Tools, Learning Aids
  • Template content:You're an experienced copywriter. Continue this sci-fi story (≥500 chars) with Qing Dynasty time-travel elements: "Sunday morning—I arrived on Mars."
  • Generated output:
    • Sunday morning—I arrived on Mars. Standing on rust-red soil beneath an ochre sky, I felt awe unlike anything Earth had ever offered.
    • Then—a colossal snow-dusted peak loomed ahead. Drawn forward, I began the steep ascent. Hours later, atop the summit, I found a cavern pulsing with eerie blue light.
    • Inside lay a vast laboratory—filled with humming machinery and figures in Qing Dynasty robes, meticulously calibrating instruments.
    • "How…?" I stammered.
    • "We are scholars of the Qing court," replied a man with a queue and spectacles. "Through chronal resonance, we crossed centuries—and worlds—to study Martian life."
    • Stunned, I joined their mission. Together, we scanned canyons, analyzed regolith, decoded atmospheric anomalies. We discovered microbial fossils—ancient, resilient, whispering secrets of cosmic kinship.
    • Our work demanded grit—but also wonder. Every discovery deepened our bond across time and space. And though Earth felt distant, purpose burned brighter than Mars' twin suns.
  • Description:Generates authentic, buyer-level product reviews.
  • Recommended scenarios:E-commerce, Product Promotion
  • Template content:You're an experienced e-commerce buyer. Write 3 glowing 5-star reviews for "Bluetooth Massage Gun", highlighting portability and value-for-money. Each ≥50 chars.
  • Generated output:
    • This Bluetooth massage gun is incredibly lightweight and compact—I carry it everywhere: gym bag, suitcase, even my laptop sleeve! Pairing via phone Bluetooth is seamless, and the price? Outstanding value. Truly a game-changer.
    • Hands down the most portable, intuitive massager I've owned. Fits effortlessly in my backpack or car cupholder. At this price point? Unbeatable ROI. My recovery just got smarter—and lighter.
    • The best-value massage tool I've bought. As an avid runner, post-workout soreness used to derail me—until this gem. Super-light, powerful, and priced fairly. Highly recommend!

Error Codes

If an API call fails and returns an error message, refer to the Application invocation reference for troubleshooting.

Frequently Asked Questions

Using GetPromptTemplate offers key advantages:
  • Separation of Logic & Content: Update and optimize prompts directly in the Bailian console—no code changes or redeployments needed.
  • Centralized Management & Collaboration: All prompts live in one place, enabling seamless teamwork (e.g., prompt engineers + developers), version control, and reuse.
  • Consistency Assurance: Guarantees identical prompt versions and structures across all application modules or services—eliminating drift caused by manual maintenance.