Create structured prompts: XML, JSON, and frameworks.
Mastering XML tags, JSON schema, and the COSTAR framework is key to structuring statements that produce reliable and consistent AI output across all models.
Mastering XML tags, JSON schema, and the COSTAR framework is key to structuring statements that produce reliable and consistent AI output across all models.
The biggest improvement in statement quality comes from structure. Not better wording. Not longer statements, but structure.
A structured command tells the AI exactly where each piece of information should be: where the instructions are, where the context is, where the examples are, and what the output format should be. This eliminates ambiguity that causes inconsistent results.
XML Tag: Platform
XML tags are the most flexible structuring tool. They work across all major AI models, and Claude is specifically trained with XML in its training data.
Basic structure
Bạn là một nhà phân tích tài chính chuyên về các chỉ số SaaS. Phân tích dữ liệu hàng quý sau đây và đưa ra những hiểu biết. Quý 1: Doanh thu: 2,1 triệu đô la, Tỷ lệ khách hàng rời bỏ: 4,2%, NRR: 112% Quý 2: Doanh thu: 2,4 triệu đô la, Tỷ lệ khách hàng rời bỏ: 3,8%, NRR: 118% Quý 3: Doanh thu: 2,9 triệu đô la, Tỷ lệ khách hàng rời bỏ: 3,1%, NRR: 125% 1. Tóm tắt (2 câu) 2. Ba xu hướng chỉ số chính (với phần trăm thay đổi) 3. Một rủi ro cần lưu ý 4. Một cơ hội cần nêu bật
Compare this to the unstructured version: "You are a financial analyst. Consider Q1: Revenue $2.1 million, customer churn rate 4.2%, NRR 112%. Q2: $2.4 million, 3.8%, 118%. Q3: $2.9 million, 3.1%, 125%. Tell me about the trends and what we should focus on."
Both contain the same information. The more structured version will yield more consistent and predictable results.
Common XML tags
| Tag | Purpose | For example |
|---|---|---|
| Defining the role/specialization of AI | Nhà khoa học dữ liệu cấp cao |
|
| What should we do? | Phân loại các yêu cầu hỗ trợ này |
|
| Basic information | Chúng tôi đã ra mắt phiên bản 2.0 vào tuần trước |
|
| Rules and limitations | Tối đa 200 từ |
|
| Few-shot examples | Input: X → Output: Y |
|
| Desired format | JSON với các trường. |
|
| Data to be processed | [đặt dữ liệu người dùng ở đây] |
✅ Quick check : You have a prompt with instructions, context, user input, and desired output formatting—all in a single paragraph. What's the risk?
Answer : Artificial intelligence (AI) can misinterpret what constitutes instructions, context, and input data. For example, if your context includes "always double-check calculations," the AI might interpret it as instructions when it's actually a description of company policy. XML tags prevent this: Content is read as background information, content is treated as commands to be followed.
JSON schema for output control.
When you need structured output that your code can parse, specify the JSON schema:
Trích xuất thông tin liên hệ từ email sau. Trả về một đối tượng JSON với các trường sau: { "name": "Họ và tên đầy đủ của người gửi", "email": "Địa chỉ email", "company": "Tên công ty (hoặc null nếu không được đề cập)", "request": "Tóm tắt một câu về những gì họ muốn", "urgency": "thấp | trung bình | cao" } Chào, tôi là Marcus Chen từ DataFlow Inc. Chúng tôi cần trợ giúp khẩn cấp về việc tích hợp API. Hệ thống sản xuất của chúng tôi đang gặp sự cố và chúng tôi cần ai đó tham gia cuộc gọi trong vòng một giờ. Số điện thoại trực tiếp của tôi là marcus@dataflow.io.
Expected output:
{ "name": "Marcus Chen", "email": "marcus@dataflow.io", "company": "DataFlow Inc.", "request": "Cần trợ giúp khẩn cấp về tích hợp API do hệ thống sản xuất gặp sự cố", "urgency": "cao" }
COSTAR Framework
COSTAR provides a complete prompt framework that works for all tasks:
| Ingredient | Its meaning | For example |
|---|---|---|
| Context | Context and situation | "We are a B2B SaaS company, launching a new feature next month." |
| Objective | Things you need | "Draft a notification email for existing customers" |
| Style | Communication methods | "Professional yet friendly, similar to Stripe's communication style." |
| T one (tone) | Emotional quality | "Excited but not overstated - confident, not in a sales pitch." |
| Audience | Who will receive it? | "The current customer is using the Pro package" |
| Response | Formatting parameters | "Email subject line + 3-paragraph email body + Call-to-action (CTA) button text" |
COSTAR in practice
Công ty chúng tôi (TechCorp) bán phần mềm quản lý dự án. Chúng tôi vừa bổ sung tính năng ưu tiên nhiệm vụ dựa trên AI. Người dùng thử nghiệm bản beta rất thích tính năng này (tỷ lệ hài lòng 92%). Chúng tôi sẽ ra mắt chính thức vào thứ Ba tuần tới. Viết email thông báo sản phẩm. Tự tin và hào hứng, nhưng không cường điệu. Không dùng từ "mang tính cách mạng" hoặc "thay đổi cuộc chơi" — hãy để tính năng tự nói lên giá trị của nó. Khách hàng hiện tại của gói Pro đã sử dụng sản phẩm trong hơn 3 tháng. Họ đã quen thuộc với giao diện. - Tiêu đề email (dưới 50 ký tự) - Đoạn văn bản trước tiêu đề (dưới 100 ký tự) - Nội dung email (3 đoạn, mỗi đoạn 2-3 câu) - Một nút CTA kèm văn bản
✅ Quick check : Two prompts generate the same content, but one uses COSTAR and the other only a paragraph. In which case is COSTAR MORE IMPORTANT?
Answer : When a prompt is reusable—used by a team, embedded in an application, or run hundreds of times—a disposable, personal prompt might not be formal. But a prompt running in a production environment or shared within a team needs to produce consistent quality regardless of who runs it. COSTAR's clear components prevent this discrepancy: Every team member uses the same context, style, and output specifications.
Combining structures
The most powerful prompts combine XML tags with COSTAR principles and JSON output:
Bạn là một nhà phân tích phản hồi khách hàng. Bạn xử lý các đánh giá sản phẩm và trích xuất thông tin chi tiết có cấu trúc. Chúng tôi bán một ứng dụng năng suất. Các đánh giá đến từ App Store. Phân tích đánh giá sau và trích xuất dữ liệu có cấu trúc. { "sentiment": "positive | negative | mixed", "topics": ["danh sách các chủ đề được đề cập"], "feature_requests": ["bất kỳ tính năng nào người dùng muốn"], "bugs_mentioned": ["bất kỳ lỗi nào được báo cáo"], "summary": "tóm tắt một câu" } {{REVIEW_TEXT}}
The placeholder text {{REVIEW_TEXT}}turns this into a template—you can replace different reviews while the structure remains the same. This is how prompts in production work: Define the structure once, only change the input.
Practice exercises
- Take a prompt you frequently use and restructure it using XML tags.
- Apply the COSTAR framework to a complex task (e.g., writing a proposal, data analysis).
- Create a JSON output schema to extract information from unstructured text.
- Compare the output of the old question with the structured version – note any differences in consistency.
Key points to remember
- Structure is more important than length - well-organized prompts produce more consistent results than long, unstructured prompts.
- XML tags create a clear distinction between instructions, context, examples, and output formatting.
- JSON schema ensures that the output can be parsed by code—essential for production applications.
- COSTAR (Context, Objective, Style, Tone, Audience, Response) includes all aspects of a complete prompt.
- Templates with placeholders ({{VARIABLE}}) allow structured prompts to be reused across different inputs.
- Claude was trained with XML tags; all main models respond well to structured prompts.
-
Question 1:
In the COSTAR framework, what does the 'S' (Style) component do?
EXPLAIN:
Style relates to the method of communication, not the content. The same information presented in a "leadership summary" style versus a "detailed technical document" will produce significantly different results—even if the data is identical. Style dictates the AI's tone: word complexity, sentence length, use of technical jargon, level of detail, and rhetorical approach. Formal or informal, technical or easy to understand, persuasive or neutral—all shape word choices, sentence structure, and overall tone.
-
Question 2:
When should you use JSON formatting instead of XML in your prompt?
EXPLAIN:
JSON is the right choice when AI output is fed into another system. If a Python script is processing AI responses, the JSON schema ensures consistent, parsable output. XML is better for human-readable prompts, where you're organizing instructions. Many developers use XML for prompt structure and JSON for output formatting—combining both strengths. JSON ensures output conforms to a defined schema that programs can use without additional parsing.
-
Question 3:
Why do XML tags improve prompt reliability?
EXPLAIN:
XML tags solve the boundary problem. Without them, a long prompt would be a jumbled block of text where instructions, context, and examples are all mixed together. With tags like ``, ``, and ``, each part is clearly delineated. The AI knows exactly what is instruction, what context to infer, and what example to follow. Instructions, context, examples, and output formatting are clearly separated so the AI cannot confuse one with the other.
Training results
You have completed 0 questions.
-- / --