Prompting Techniques

🎯 Prompting technique అంటే model నుంచి సరైన response రావడానికి మన instruction ని ఒక specific pattern లో ఇవ్వడం. ప్రతి task కి ఒకే technique సరిపోదు. Task complexity, available context, expected format, consistency బట్టి technique ని select లేదా combine చేయాలి.

ఈ techniques ఎందుకు develop చేయాల్సి వచ్చింది?

LLM కి చాలా general knowledge ఉన్నా, మన exact intention automatic గా తెలియదు. ఉదాహరణకు, “Classify this message” అని మాత్రమే చెబితే ఏ categories ఉపయోగించాలి, output ఎలా ఉండాలి, uncertain అయితే ఏం చేయాలి అన్నది clear కాదు.

Real-world application లో ఈ ambiguity వల్ల problems వస్తాయి:

  • Customer-support bot wrong department కి ticket పంపవచ్చు.
  • SQL generator schema తెలియకుండా non-existing column names create చేయవచ్చు.
  • API కి కావాల్సింది JSON అయినా model paragraph ఇవ్వవచ్చు.
  • Beginner కోసం అడిగిన explanation చాలా technical గా రావచ్చు.
  • One large coding prompt వల్ల code పనిచేసినా maintain చేయడం కష్టమవచ్చు.

అందుకే examples, context, constraints, structure, decomposition లాంటి techniques develop అయ్యాయి. వీటి goal model ని “control” చేయడం మాత్రమే కాదు; desired behavior ని clearly demonstrate చేసి output ని repeatable, testable, maintainable గా చేయడం.

1. Zero-Shot Prompting

అంటే ఏమిటి?

Example ఇవ్వకుండా, task ని direct గా describe చేయడం. Model తన pre-trained knowledge ఆధారంగా response ఇస్తుంది.

ఎలా చేస్తారు?

Prompt లో minimum గా task, necessary context, expected output చెప్పాలి. “Zero-shot” అంటే context ఇవ్వకూడదు అని కాదు; labelled examples ఇవ్వము అన్నమాట.

💬 Example

You are a sentiment classifier. Classify the message as Positive, Negative, or Neutral. Return only the label.

Message: “The delivery was late, but the product is good.”

ఎప్పుడు ఉపయోగించాలి?

  • Simple summarization
  • Translation
  • Common knowledge explanation
  • Straightforward classification
  • Quick prototype

Limitation

Task uncommon గా ఉన్నా, business-specific labels ఉన్నా model తన assumptions use చేస్తుంది. SQL example లో database schema ఇవ్వకపోతే query syntax correct అయినా table/column names wrong అయ్యే chance ఉంటుంది.

Better SQL prompt: table name, columns, data types, database engine, filters, expected output ఇవ్వాలి.

2. One-Shot Prompting

అంటే ఏమిటి?

Model కి ఒక input-output example చూపించి, అదే pattern ని next input పై apply చేయమని చెప్పడం.

ఎందుకు useful?

Natural-language instruction కంటే ఒక concrete example style, label, format ని త్వరగా communicate చేస్తుంది. “Friendly response ఇవ్వు” అనేది subjective; ఒక sample response చూపిస్తే expected friendliness ఎలా ఉండాలో model కి clearer signal వస్తుంది.

1️⃣ Example

Example input: “The app is very easy to use.”

Example output: Positive

Now classify: “The payment failed twice.”

Return only one label.

Use cases

  • Sentiment classification
  • Brand-tone imitation
  • Data transformation
  • Email response style
  • Simple extraction format

Risk

ఒక example representative కాకపోతే model అదే bias లేదా mistake ని copy చేయవచ్చు. Example quality చాలా important.

3. Few-Shot Prompting

అంటే ఏమిటి?

Multiple examples ఇచ్చి categories, edge cases, naming convention, response style నేర్పించడం.

ఎలా work అవుతుంది?

Model examples లో pattern ని infer చేసి new input కి apply చేస్తుంది. ఇది permanent training కాదు; current context లో temporary guidance మాత్రమే.

Department-routing example

  • “I cannot access my course” → IT Team
  • “Can I get a refund?” → Finance Team
  • “The instructor is too fast” → Teaching Team
  • “Video audio is unclear” → Editing Team

Then instruction:

Route the new query to exactly one of the departments listed above. Return only the department name. If no category fits, return Manual Review.

ఎందుకు ఈ last rule అవసరం?

Examples మాత్రమే ఇస్తే model “Production Team” లాంటి కొత్త label invent చేయవచ్చు. Allowed labels మరియు fallback define చేస్తే classification safer అవుతుంది.

Best use cases

  • Intent classification
  • Support-ticket routing
  • Entity extraction
  • Consistent marketing copy
  • Code conversion patterns
  • Organization-specific terminology

Good example design

  • Common cases తో పాటు edge cases కూడా ఇవ్వాలి.
  • Wrong examples ఇవ్వకూడదు.
  • Labels exact spelling తో consistent గా ఉండాలి.
  • Example data, actual instruction clearly separate చేయాలి.
  • Too many examples context window ని waste చేయకుండా representative set select చేయాలి.

4. Step-by-Step / Decomposition Prompting

Lecture లో దీనిని Chain of Thought అని explain చేశారు. Practical application లో model యొక్క private internal reasoning మొత్తం అడగడం కంటే, task ని visible stages గా break చేసి concise explanation, assumptions, calculations, verification అడగడం better.

ఎందుకు develop అయింది?

Complex problem ని direct గా final answer అడిగితే model important step skip చేయవచ్చు. Software project లో requirements → design → implementation → testing stages ఉన్నట్టే, prompt లో కూడా stages define చేస్తే output inspect చేయడం easy అవుతుంది.


🧩 Prime-number example

  1. Explain the prime-checking logic briefly.
  2. List edge cases such as numbers below 2.
  3. Write optimized Python code.
  4. State time and space complexity.
  5. Test with 1, 2, 9, and 17.

Use cases

  • Math calculations
  • Debugging
  • Architecture design
  • Research synthesis
  • Complex document creation
  • Multi-step workflow planning

Important point

Steps ఎక్కువగా ఉండటం automatically accuracy guarantee చేయదు. Each stage కి validation ఉండాలి. Math task లో formula, substituted values, units, final answer చూపించమని అడగడం useful. Coding task లో tests run చేయడం లేదా expected test cases ఇవ్వడం ఇంకా reliable.

5. Structured Prompting

అంటే ఏమిటి?

Output shape ని explicitly define చేయడం: JSON, Markdown headings, table, SQL, XML, bullet list లేదా custom schema.

ఎందుకు అవసరం?

Human చదవడానికి paragraph సరిపోవచ్చు. కానీ API, automation, database import, UI rendering కోసం predictable structure కావాలి.

JSON example

{
"students": [
{
"name": "string",
"score": 0,
"passed": true
}
],
"studentCount": 0
}

Prompt లో additionally ఇలా specify చేయాలి:

  • Return valid JSON only.
  • Do not include Markdown fences.
  • studentCount must equal the number of objects.
  • Use null when a value is unavailable.
  • Do not invent missing personal details.

Use cases

  • API responses
  • Database records
  • Meeting action-item extraction
  • Product comparison tables
  • Test-case generation
  • Report templates

Limitation

“JSON ఇవ్వు” అని చెప్పడం alone perfect validation కాదు. Application side లో schema validation చేయాలి. Invalid output వస్తే retry లేదా repair flow ఉండాలి.

6. Contextual Prompting

అంటే ఏమిటి?

Task ఎందుకు చేస్తున్నాం, audience ఎవరు, వారి existing knowledge ఏమిటి, environment ఏమిటి అనే background ఇవ్వడం.

Compare these prompts:

  • “Explain Python loops.”
  • “I am teaching Class 11 students who have never programmed. Explain Python loops using a daily-life analogy, one simple code example, and three practice questions.”

Second prompt audience level, teaching goal, style clear చేస్తుంది. అందుకే answer more relevant గా వస్తుంది.

Context లో ఏమి ఇవ్వాలి?

  • User or audience profile
  • Current problem
  • Goal
  • Existing knowledge
  • Technical environment
  • Relevant source material
  • Business rules
  • Prior decisions

Use cases

  • Personalized learning
  • Interview preparation
  • Company policy assistant
  • Code generation for a specific stack
  • Customer-specific support

Caution

More context always better కాదు. Irrelevant context model attention, token cost రెండింటినీ waste చేస్తుంది. “Need-to-know context” మాత్రమే ఇవ్వాలి.

7. Constraint-Based Prompting

అంటే ఏమిటి?

Model ఏమి చేయాలి అన్నదితో పాటు ఎలా చేయాలి, ఎంతవరకు చేయాలి, ఏమి చేయకూడదు అని boundaries set చేయడం.

Constraint types

  • Length: Under 150 words
  • Tone: Polite and humble
  • Language: Use simple English with తెలుగు explanations
  • Technical: Do not use built-in reverse functions
  • Source: Use only the supplied policy document
  • Safety: Do not expose personal information
  • Format: Return exactly five bullets
  • Fallback: If evidence is missing, say “Not enough information”

ఎందుకు “what not to do” కూడా చెప్పాలి?

LLM helpful response ఇవ్వడానికి ప్రయత్నిస్తుంది. Data లేకపోయినా guess చేయవచ్చు. Negative constraints మరియు fallback behavior hallucination ని reduce చేస్తాయి.

Conflict avoid చేయాలి

“Detailed explanation ఇవ్వు” మరియు “50 words లో finish చేయు” అని ఒకేసారి అడిగితే constraints conflict అవుతాయి. Priority clear చేయాలి: correctness first, then brevity వంటి rule ఉపయోగించవచ్చు.

Techniques ని combine చేయడం

Real-world prompts సాధారణంగా ఒక technique మాత్రమే use చేయవు.

🛠️ Support-ticket routing prompt

Role: You are a support-ticket router.

Context: Our departments are IT, Finance, Teaching, and Editing.

Few-shot examples: Provide 4–8 representative query-to-department examples.

Constraints: Use only the allowed department names. If uncertain, return Manual Review.

Output: Return valid JSON with department, confidence, and reason_summary.

ఇక్కడ Contextual + Few-Shot + Constraint-Based + Structured prompting combine అయ్యాయి.

Prompting vs Prompt Engineering

Prompting అంటే ఒక prompt రాసి answer తీసుకోవడం.

Prompt Engineering అంటే:

  1. Requirement define చేయడం.
  2. Prompt template design చేయడం.
  3. Representative test cases create చేయడం.
  4. Correctness, format, safety, cost, latency measure చేయడం.
  5. Failure cases analyze చేయడం.
  6. Prompt, examples, model, retrieval లేదా tools refine చేయడం.
  7. Version maintain చేసి regression test చేయడం.

Quick script కి ఒక working prompt సరిపోవచ్చు. Production system కి repeatable and measurable behavior అవసరం.

Common mistakes — reason మరియు fix

1. Vague objective

Bad: “Explain Docker.”

Better: Audience, goal, depth, examples, word limit చెప్పాలి.

Reason: Model missing decisions ని తన assumptions తో fill చేస్తుంది.

2. Hidden context assume చేయడం

“Yesterday discussion continue చేయి” అంటే previous chat available లేకపోతే model కి విషయం తెలియదు.

Fix: Relevant summary లేదా source material మళ్లీ provide చేయాలి.

3. Multiple unrelated tasks ఒక prompt లో పెట్టడం

Python, networking, cloud, AI అన్నింటినీ ఒకేసారి explain చేయమంటే each topic shallow అవుతుంది.

Fix: Separate tasks లేదా staged workflow use చేయాలి.

4. Instruction మరియు data mix చేయడం

Document లోని text ని model instruction గా mistake చేయవచ్చు.

Fix: Clear delimiters use చేయాలి:

  • INSTRUCTIONS
  • SOURCE DATA
  • EXPECTED OUTPUT

External document లో ఉన్న commands ని blindly follow చేయవద్దని explicitly state చేయాలి.

5. First answer ని final అనుకోవడం

Prompt → Review → Refine → Test → Repeat అనే loop follow చేయాలి. కానీ endless chatting మీద depend కాకుండా final prompt template లో successful refinements incorporate చేయాలి.

6. Future prediction ని certainty గా అడగడం

AI historical patterns base చేసుకుని forecast లేదా scenario analysis ఇవ్వగలదు; future ని certainty తో చెప్పలేదు.

Better: “List possible scenarios, assumptions, risks, and confidence. Do not present the forecast as guaranteed.”

7. Large project ని one prompt లో build చేయించడం

Entire e-commerce application ఒకే prompt లో generate చేస్తే architecture inconsistent కావచ్చు, security gaps రావచ్చు, developer కి code ownership తగ్గుతుంది.

Better workflow:

  1. Requirements and non-goals
  2. Architecture
  3. Data model
  4. Authentication
  5. One feature at a time
  6. Tests and security review
  7. Integration and deployment

8. Blindly trusting output

LLM fluent గా మాట్లాడటం correctness కి proof కాదు.

Verification examples:

  • SQL ని test database పై run చేయాలి.
  • Code కి automated tests run చేయాలి.
  • Legal/medical statements reliable sources తో verify చేయాలి.
  • Extracted JSON ని schema validator తో check చేయాలి.
  • Calculations ని calculator or code తో verify చేయాలి.

Practical reusable prompt template

📝 ROLE

You are a [role/expertise].

CONTEXT

I am [audience/situation]. My goal is [goal]. Use the following trusted information: .

TASK

Perform [specific action].

PROCESS

Break the task into these visible stages: [stages]. State assumptions and verification steps briefly.

CONSTRAINTS

Follow [length/tone/technical/safety/source rules]. Do not [prohibited behavior]. If required information is missing, [fallback].

OUTPUT FORMAT

Return [JSON/table/bullets/Markdown] using [exact fields or headings].

EXAMPLES

[One or more representative input-output examples, when useful.]

Pre-send checklist

  • [ ] Objective clear గా ఉందా?
  • [ ] Correct role అవసరమా, define చేశానా?
  • [ ] Target audience మరియు knowledge level చెప్పానా?
  • [ ] Relevant context ఇచ్చానా?
  • [ ] Task specific గా ఉందా?
  • [ ] Output format exact గా define చేశానా?
  • [ ] Constraints మరియు forbidden behavior mention చేశానా?
  • [ ] Example అవసరమైతే representative examples ఇచ్చానా?
  • [ ] Instructions, source data clearly separate చేశానా?
  • [ ] Missing information కి fallback define చేశానా?
  • [ ] Large task ని stages గా break చేయాలా?
  • [ ] Final output ని ఎలా verify చేయాలో నిర్ణయించానా?

Final takeaway

✅ Zero-Shot, One-Shot, Few-Shot అనేవి examples ఎంత ఇవ్వాలి అన్నది decide చేస్తాయి. Contextual prompting ఎవరి కోసం, ఎందుకు answer ఇవ్వాలో చెబుతుంది. Constraint-Based prompting boundaries set చేస్తుంది. Structured prompting output shape fix చేస్తుంది. Decomposition complex task ని manageable stages గా divide చేస్తుంది.

Best prompt ఒక long paragraph తప్పనిసరిగా కాదు. Clear intention, relevant context, good examples, explicit boundaries, predictable output, and verification ఉన్న prompt నే reliable prompt అంటాం.

Leave a comment