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

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:

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

  1. Take a prompt you frequently use and restructure it using XML tags.
  2. Apply the COSTAR framework to a complex task (e.g., writing a proposal, data analysis).
  3. Create a JSON output schema to extract information from unstructured text.
  4. 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.

-- / --

Related posts
  • What is a JSON file?

    json (javascript object notation) is an open standard file format for sharing data that uses human-readable text to store and transmit data.
  • Difference between JSON and XML

    json and xml are the two main data exchange standards that web 2.0 applications commonly use. they are data formats that allow sending and receiving data between the client and the web server.
  • Instructions for importing JSON into Google Sheets

    json is a standard protocol for sending data between applications. in this tutorial, tipsmake.com.com will show you how to import json data into google sheets using a free, open source script available on github.
  • XML and information on demand

    recently, we often hear the concept of 'information on demand.' information on demand is understood in the sense that the organization's information system must meet all user requirements, from leadership to professional staff; from statistical information, forecast to detailed information for daily activities ...
  • HTML and XHTML

    xhtml is html written in xml language.
  • Trick to create XML files in Word 2003

    many people believe that word is not an appropriate tool for editing xml files, but the following tips will help you edit xml files on word very effectively.
Other Program articles
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup