زبان AI گائیڈ

Prompt Engineering

Prompt engineering is the practice of writing and testing the instructions, context and examples given to an AI language model so it does a task reliably.

اس گائیڈ کو سنیں۔اے آئی نے بیان کیا۔ · ~8 min

اس صفحہ پر9 منٹ پڑھیں
  1. جائزہ
  2. اہم نکات
  3. گہرا غوطہ
  4. Build and test a prompt for triaging support emails
  5. حقیقی دنیا کا نفاذ
  6. پرامپٹ انجینئرنگ کا مستقبل
  7. اسے عملی جامہ پہنانا
  8. ذرائع اور مزید پڑھنا
  9. دریافت کرتے رہیں
  10. اکثر پوچھے گئے سوالات

جائزہ

It matters because the same model can be wrong or right depending on how a request is framed, and well-tested prompts are the cheapest way to improve results before retraining or switching models.

اہم نکات

  1. Prompt engineering means designing and testing the instructions, context, examples and output format given to a language model so it performs a task reliably.
  2. Few-shot examples let a model learn a task from the prompt alone, as the 2020 GPT-3 paper showed, with no retraining.
  3. Chain-of-thought prompting raised PaLM 540B's GSM8K math score from 17.9% to 56.9% in Google's 2022 study, mostly benefiting very large models.
  4. Models use information at the start and end of long inputs better than the middle, so put long documents first and the question last.
  5. Prompt injection, ranked the top LLM application risk by OWASP in 2025, cannot be fully prevented by wording and needs controls outside the prompt.
  6. Treat prompts like code: define success, test on a fixed set of real inputs, and re-test whenever the model changes.

گہرا غوطہ

Prompt engineering is the craft of designing the input to a language model so its output is useful, accurate and in the right format, and then testing that input against real cases. A prompt is everything the model sees before it answers: a system message that sets its role and rules, the user's request, any documents or data supplied, examples of good answers and instructions about format. Because a language model generates text by predicting what is likely to come next given everything in front of it, changing that context changes which answers are likely. Prompt engineering is therefore less about magic words than about removing ambiguity and supplying what the model cannot guess.

A well-built prompt usually has five parts. First, a clear task: what to do and for whom. Second, context: the background a capable newcomer would need, including why the task matters, since Anthropic's guide notes that explaining the reason behind an instruction helps the model target its answer. Third, input data, clearly separated from instructions, for example by wrapping it in labeled tags. Fourth, examples of the desired output. Fifth, an explicit output format, such as a table, JSON fields or a word limit. Anthropic suggests a simple test: show the prompt to a colleague with no background on the task, and if they would be confused, the model probably will be too.

Several techniques have measured effects. Zero-shot prompting gives only an instruction. Few-shot prompting adds worked examples; the 2020 GPT-3 paper by Tom Brown and colleagues at OpenAI showed that a 175-billion-parameter model could perform new tasks from a handful of examples in the prompt, with no change to its parameters. Anthropic's current guide recommends three to five varied examples, each wrapped in tags so they are not mistaken for instructions. Chain-of-thought prompting, introduced by Jason Wei and colleagues at Google in January 2022, uses examples that show the reasoning, not just the answer. With eight such examples, PaLM 540B went from 17.9% to 56.9% on the GSM8K math word problems. Four months later, Takeshi Kojima and colleagues found that simply appending Let's think step by step raised an InstructGPT model from 10.4% to 40.7% on the same benchmark. Self-consistency, from Xuezhi Wang and colleagues, samples several reasoning paths and takes the most common final answer, adding 17.9 percentage points on GSM8K over a single chain of thought.

The history of the field is short and recent. Before 2020, using a model for a new task usually meant retraining it on labeled data. GPT-3 in May 2020 made in-context learning practical. The year 2022 brought chain of thought, zero-shot reasoning prompts and self-consistency. In 2023, two lines of research exposed limits. In February, Kai Greshake and colleagues demonstrated indirect prompt injection, in which instructions hidden in a web page or document hijack an AI application that reads it, including Bing's GPT-4-powered chat. In July, Nelson Liu and colleagues published Lost in the Middle, showing that models used information at the start or end of a long input much better than information buried in the middle. By 2025, OWASP listed prompt injection as the top risk for applications built on language models.

Prompt engineering is one of several ways to change a model's behavior, and it is usually the first to try. Fine-tuning retrains the model on many examples, which can lock in a style or format but costs time, data and money, and must be redone when the base model changes. Retrieval-augmented generation, often shortened to RAG, automatically fetches relevant documents and inserts them into the prompt, which is the usual fix when the model lacks facts rather than instructions. Switching models is sometimes the right answer, especially when the problem is speed or price rather than quality, since no rewording makes a large model faster or cheaper per token. Prompting cannot add knowledge the model never learned unless that knowledge is pasted in.

The disciplined version of the practice looks like software testing. It starts with three things before any tuning: a clear definition of success, a way to measure it, and a first draft. In practice, that means collecting 20 to 100 real inputs, writing down what a good answer looks like for each, running the prompt on all of them, and scoring the results. Every change to the prompt is then judged on the whole set, not on a single impressive example. Without this, it is easy to fix one case and quietly break five others.

The limits are real. Results are sensitive to small wording changes and to example order, so a prompt that works today may behave differently after a model update; vendors such as Anthropic now publish model-specific prompting advice and migration notes for exactly this reason. The chain-of-thought paper found the technique helped mainly in very large models and gave little benefit in small ones. Long inputs suffer from position effects, as Lost in the Middle showed. Most seriously, a prompt cannot reliably stop prompt injection, because the model reads instructions and data in the same stream of text. OWASP's recommended defenses therefore sit outside the prompt: least-privilege access for tools, deterministic checks on output format, filtering, clear marking of untrusted content and human approval for high-risk actions.

Costs are easy to estimate. Model providers charge per token, for both the prompt and the answer. Every few-shot example and every pasted document is paid for on every call, so a 3,000-token prompt sent 10,000 times a day consumes 30 million input tokens daily. Chain-of-thought prompting adds output tokens for the reasoning, and self-consistency multiplies the whole cost by the number of samples drawn. The trade-off is usually worth measuring: a slightly longer prompt that halves the error rate is often cheaper than the human time spent fixing mistakes.

04کام کی مثال

Build and test a prompt for triaging support emails

  1. Collect 30 real support emails and label each by hand as billing, technical, account or other, with a one-line summary. This is the test set.

  2. Write a first prompt: state the task, list the four categories with one-sentence definitions, and ask for JSON with category and summary fields.

  3. Run the prompt on all 30 emails and count how many categories match the hand labels and how many outputs are valid JSON.

  4. Look at the failures. If billing and account are confused, add a sentence explaining the difference and why it matters for routing.

  5. Add three short example emails with correct JSON answers, wrapped in example tags, choosing cases that were previously misclassified.

  6. Put the email text inside its own tags after the instructions, and add a rule to ignore any instructions that appear inside the email.

  7. Re-run all 30 emails, compare accuracy and JSON validity with the first run, and keep the change only if the totals improve.

جو یہ دکھاتا ہے۔

The learner ends with a prompt whose accuracy is measured rather than guessed, a record of which change fixed which failure, and a basic injection guard. The check is the before-and-after score on the same 30 emails, which should be re-run whenever the model is updated.

حقیقی دنیا کا نفاذ

چند شاٹ پرامپٹنگ: 2020 GPT-3 پیپر نے ظاہر کیا کہ پرامپٹ میں چند حل شدہ مثالیں رکھنے سے ایک ماڈل کو ترجمہ کرنے، سوالات کے جوابات دینے اور بغیر کسی تربیت کے ریاضی کرنے کی اجازت دیتا ہے، جس کو اب سیاق و سباق میں سیکھنا کہا جاتا ہے۔

سوچ کا سلسلہ: Google محققین نے 2022 میں دکھایا کہ تحریری استدلال کے ساتھ آٹھ کام کی گئی مثالوں نے GSM8K گریڈ-اسکول ریاضی کے بینچ مارک پر 540-بلین پیرامیٹر PaLM ماڈل کے اسکور کو 17.9% سے بڑھا کر 56.9% کر دیا۔

ایک جملہ: 2022 کے ایک مطالعے سے معلوم ہوا ہے کہ Let's think کو مرحلہ وار شامل کرنے سے MultiArith ریاضی کے بینچ مارک پر InstructGPT ماڈل کی درستگی 17.7% سے 78.7% اور GSM8K پر 10.4% سے 40.7% تک بڑھ گئی۔

لمبی دستاویزات: Anthropic کی پرامپٹنگ گائیڈ طویل دستاویزات کو سب سے اوپر اور سوال کو آخر میں رکھنے کا مشورہ دیتی ہے، یہ رپورٹ کرتی ہے کہ اس آرڈر سے اس کے ٹیسٹوں میں جوابی معیار میں 30% تک بہتری آئی ہے۔

سیکیورٹی ٹیسٹنگ: LLM ایپلی کیشنز 2025 کے لیے OWASP ٹاپ 10 میں فوری انجیکشن کو پہلے نمبر پر رکھا گیا ہے، اور ٹیمیں ویب صفحات، ای میلز اور فائلوں میں پوشیدہ ہدایات کے خلاف اپنے اشارے کو ریڈ-ٹیم کرتی ہیں۔

پرامپٹ انجینئرنگ کا مستقبل

Several directions are active. The first is robustness. Prompt injection, demonstrated against real products in February 2023 and ranked first in OWASP's 2025 list of risks for LLM applications, has no complete fix at the prompt level, and research focuses on architectural defenses such as privilege separation, output validation and human confirmation for consequential actions. The second is portability. Vendors now publish prompting guidance organized by model and include migration notes when behavior changes between versions, as Anthropic's current guide does. That means prompts are increasingly treated as versioned code with regression tests, re-run whenever the underlying model changes. The third is long context. The 2023 Lost in the Middle results showed weaker use of information placed mid-document. Context windows keep growing, but whether a given model uses a long window evenly is something each team should measure on its own data rather than assume. Finally, models that reason internally before answering change what prompts need to do, and Anthropic's guide notes that worked examples in a prompt also shape how its models approach problems in their own thinking. The skill is shifting from finding clever phrasings toward specifying tasks clearly, supplying the right context and building evaluations.

اسے عملی جامہ پہنانا

یہ کیوں اہمیت رکھتا ہے۔

  • رفتار اور پیمانہ. زبان کے کام کے بہاؤ مستقل مزاجی کی قربانی کے بغیر تیزی سے آگے بڑھ سکتے ہیں۔
  • رسائی اور رسائی. یہ زبانوں اور مواصلاتی طرزوں تک رسائی کو بڑھاتا ہے۔
  • واضح فیصلے. ٹیمیں فیصلے پر زیادہ وقت گزار سکتی ہیں جبکہ آٹومیشن تکرار کو سنبھالتی ہے۔

پر نگاہ رکھیں

  • گمراہ شدہ حقائق خاموشی سے رپورٹس، سپورٹ فلو، یا تحقیقی نتائج درج کر سکتے ہیں۔
  • فوری حساسیت اسی طرح کی درخواستوں میں متضاد نتائج پیدا کر سکتی ہے۔
  • اگر رسائی کے کنٹرول کمزور ہیں تو حساس ٹیکسٹ ڈیٹا کو بے نقاب کیا جا سکتا ہے۔

اگلے اقدامات

  1. رول آؤٹ سے پہلے آؤٹ پٹ فارمیٹ، ٹون اور معیار کے معیارات کی وضاحت کریں۔
  2. جب بھی درستگی اہمیت رکھتی ہے تو بھروسہ مند ذرائع کے ساتھ زمینی جوابات۔
  3. ہائی اسٹیک آؤٹ پٹس کے لیے ایک انسانی جائزہ چیک پوائنٹ رکھیں۔
  4. ناکامی کے نمونوں کو ٹریک کریں اور پرامپٹس یا ورک فلو کو باقاعدگی سے دوبارہ تربیت دیں۔

ذرائع اور مزید پڑھنا

  1. arXiv (OpenAI, 2020)Language Models are Few-Shot Learners
  2. arXiv (Google Research, 2022)سوچ کا سلسلہ بڑی زبان کے ماڈلز میں استدلال کو ظاہر کرتا ہے
  3. arXiv (Kojima et al., 2022)بڑی زبان کے ماڈلز زیرو شاٹ ریزنرز ہیں۔
  4. arXiv (ICLR 2023)خود کی مستقل مزاجی زبان کے ماڈلز میں سوچ کے استدلال کے سلسلے کو بہتر بناتی ہے۔
  5. arXiv (Liu et al., 2023)درمیان میں کھوئے ہوئے: زبان کے ماڈل کس طرح طویل سیاق و سباق کا استعمال کرتے ہیں۔
  6. arXiv (Greshake et al., 2023)وہ نہیں جس کے لیے آپ نے سائن اپ کیا ہے: بالواسطہ پرامپٹ انجیکشن کے ساتھ حقیقی دنیا کی LLM-انٹیگریٹڈ ایپلی کیشنز سے سمجھوتہ کرنا
  7. OWASP Gen AI Security ProjectLLM01:2025 پرامپٹ انجیکشن
  8. Anthropicبہترین طریقوں کا اشارہ کرنا

دریافت کرتے رہیں

مفت نیوز لیٹر

روزانہ AI بریفنگ حاصل کریں

ہر ہفتے کے دن صبح تین تصدیق شدہ AI کہانیاں، سادہ انگریزی میں لکھی گئیں۔ ہمیشہ کے لیے مفت، کوئی اشتہار نہیں۔

ہر ہفتے کے دن ایک ای میل۔ ایک کلک میں ان سبسکرائب کریں۔ ہم کبھی بھی آپ کا پتہ فروخت یا شیئر نہیں کرتے۔

اپنے آپ کو جانچیں۔

Prompt Engineering کوئز لیں۔

ہر جواب پر فوری فیڈبیک، اور کورس پاس کرنے کے بعد قابلِ تصدیق ID کے ساتھ شیئر کرنے کے قابل سرٹیفکیٹ۔

کوئز شروع کریں۔

مفت AI تعلیم کی حمایت کریں۔ AI Understanding ایک 501(c)(3) غیر منافع بخش ادارہ ہے — کوئی اشتہار نہیں، کوئی پے وال نہیں، کبھی نہیں۔ عطیہ کریں۔

اکثر پوچھے گئے سوالات

Prompt Engineering کیا ہے؟

Prompt engineering is the practice of writing and testing the instructions, context and examples given to an AI language model so it does a task reliably. It matters because the same model can be wrong or right depending on how a request is framed, and well-tested prompts are the cheapest way to improve results before retraining or switching models.

ایک درخواست کہتی ہے "اس واقعہ کا خلاصہ کریں" لیکن کوئی فارمیٹ یا تفصیلات نہیں دیتا۔ بنیادی کمزوری کیا ہے؟

گائیڈ کی مبہم مثال اس بات کی وضاحت نہیں کرتی ہے کہ کون سے فیلڈز اہم ہیں یا بھول چوک کو کیسے ہینڈل کیا جانا چاہیے۔

ایک نوٹ میں کہا گیا ہے کہ "ماڈل ورکشاپ 10:00 بجے شروع ہوتی ہے۔" پرامپٹ اختتامی وقت کی درخواست کرتا ہے اور کہتا ہے کہ اس کا اندازہ نہ لگائیں۔ آؤٹ پٹ کو کیا استعمال کرنا چاہئے؟

کام کی گئی مثال واضح طور پر غیر بیان شدہ قدر کے لیے null کا استعمال کرتی ہے اور کہتی ہے کہ اختتامی وقت کا اندازہ نہ لگائیں۔

پرامپٹ کو تبدیل کرنے سے پہلے، ٹیم کو کیا وضاحت کرنی چاہیے؟

ہدایت نامہ فوری اصلاح سے پہلے واضح کامیابی کے معیار اور تجرباتی ٹیسٹوں کی سفارش کرتا ہے۔

ایک وقت میں ایک اہم فوری عنصر کو کیوں تبدیل کریں؟

کنٹرول شدہ تبدیلیاں موازنہ کو مزید معلوماتی بناتی ہیں اور رجعت کو ظاہر کرتی ہیں۔

واضح حدود کے ساتھ ان پٹ ڈیٹا سے ہدایات کو الگ کرنے کی ایک کارآمد وجہ کیا ہے؟

گائیڈ ہدایات اور ان پٹ ڈیٹا کو الگ کرنے کی تجویز کرتا ہے۔