AI प्रॉम्प्ट इंजीनियरिंग · पाठ

आउटपुट-से-इनपुट प्रारूप

चरण 2 में डालने के लिए चरण 1 से संरचित डेटा निकालें।

पाठ 2, कुल 4 में से13 चरण

आउटपुट-से-इनपुट प्रारूप, CoddyKit पर AI प्रॉम्प्ट इंजीनियरिंग का एक निःशुल्क पाठ है। यह 4 में से 2वाँ पाठ है। इस अध्ययन पथ के 3 तक कोई भी पाठ पूरा पढ़ना निःशुल्क है — इसके बाद CoddyKit PRO हर पाठ अनलॉक करता है, साथ ही अंतर्निर्मित कोड संपादक और चौबीसों घंटे एआई शिक्षक के साथ व्यावहारिक अभ्यास भी उपलब्ध कराता है। यह AI प्रॉम्प्ट इंजीनियरिंग सीखने के मार्ग का हिस्सा है और आपकी प्रगति वेब तथा CoddyKit ऐप पर सिंक होती रहती है। AI प्रॉम्प्ट इंजीनियरिंग पाठ्यक्रम में कुल 4 पाठ शामिल हैं।

मुख्य चुनौती: निकालना और डालना

प्रॉम्प्ट चेन में चरण 1 पाठ तैयार करता है। चरण 2 को उस पाठ के किसी विशिष्ट हिस्से की इनपुट के रूप में आवश्यकता होती है। चुनौती यह है कि चरण 1 के आउटपुट से ठीक सही फ़ील्ड को विश्वसनीय रूप से निकाला जाए और उसे चरण 2 के प्रॉम्प्ट में साफ़-सुथरे ढंग से डाला जाए।

यदि चरण 1 असंरचित गद्य लौटाता है, तो निष्कर्षण अस्थिर हो जाता है। समाधान यह है कि चरण 1 के प्रॉम्प्ट को संरचित आउटपुट — सामान्यतः JSON — लौटाने के लिए डिज़ाइन किया जाए, जिसे प्रोग्राम के माध्यम से पार्स करके डाला जा सके।

मशीन द्वारा उपयोग के लिए चरण 1 की रूप-रचना

किसी शृंखला को इनपुट देने के लिए बनाए गए प्रॉम्प्ट को हमेशा संरचित डेटा लौटाना चाहिए। प्रॉम्प्ट में सटीक JSON स्कीमा निर्दिष्ट करें:

import anthropic
import json

client = anthropic.Anthropic(api_key='YOUR_API_KEY')

step1_prompt = '''
<task>
Analyze the customer review below.
</task>

<review>
The onboarding was confusing and took 3 hours. The core feature works great though.
</review>

<output_format>
Return ONLY a JSON object. No other text.
{
  "sentiment": "positive|negative|mixed",
  "issues": ["string"],
  "positives": ["string"],
  "priority": "high|medium|low"
}
</output_format>
'''

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=300,
    messages=[{'role': 'user', 'content': step1_prompt}]
)
print(response.content[0].text)

चरण 1 के आउटपुट का विश्लेषण

जब चरण 1 JSON लौटाए, तो उसे पाइथन में पार्स करें और चरण 2 के लिए आवश्यक फ़ील्ड निकालें:

import json

def parse_step1_output(raw_text):
    # Models sometimes wrap JSON in extra text -- strip it
    text = raw_text.strip()
    # Find the first { and last } to extract JSON object
    start = text.find("{")
    end = text.rfind("}")
    if start != -1 and end != -1 and end > start:
        text = text[start:end+1]
    try:
        return json.loads(text)
    except json.JSONDecodeError as e:
        raise ValueError("Step 1 output is not valid JSON: " + str(e))

# Example usage
raw = '{"sentiment": "mixed", "issues": ["confusing onboarding"], "positives": ["core feature"], "priority": "high"}'
parsed = parse_step1_output(raw)
print(parsed['issues'])
print(parsed['priority'])

निकाले गए फ़ील्ड को चरण 2 में सम्मिलित करना

पार्स करने के बाद, विशिष्ट फ़ील्ड को चरण 2 के प्रॉम्प्ट टेम्पलेट में सम्मिलित करें। पाइथन f-string या टेम्पलेट चर का उपयोग करें:

def build_step2_prompt(parsed_step1):
    issues = '\n'.join(f'- {issue}' for issue in parsed_step1['issues'])
    priority = parsed_step1['priority']
    sentiment = parsed_step1['sentiment']

    return f'''
<context>
A customer review was analyzed. Overall sentiment: {sentiment}. Priority: {priority}.
</context>

<task>
Write a customer support response addressing these specific issues:
{issues}
Acknowledge the positives before addressing the issues.
</task>

<output_format>
Plain text response, 3 sentences maximum, professional tone.
</output_format>
'''

parsed = {'sentiment': 'mixed', 'issues': ['confusing onboarding'], 'priority': 'high', 'positives': ['core feature']}
print(build_step2_prompt(parsed))

पूर्ण दो-चरणीय शृंखला

पार्स और सम्मिलन को एक पूर्ण दो-चरणीय पाइपलाइन में संयोजित करना:

import anthropic, json

client = anthropic.Anthropic(api_key='YOUR_API_KEY')

def call(prompt, max_tokens=500):
    r = client.messages.create(
        model='claude-opus-4-5', max_tokens=max_tokens,
        messages=[{'role': 'user', 'content': prompt}]
    )
    return r.content[0].text

def review_response_chain(review_text):
    # Step 1: Analyze
    step1 = call(f'Analyze this review. Return JSON: {{"sentiment": str, "issues": [str], "priority": str}}\n\nReview: {review_text}')
    parsed = json.loads(step1.strip())

    # Inject into Step 2
    issues_str = ', '.join(parsed['issues'])
    step2_prompt = f'Write a 2-sentence support reply. Issues to address: {issues_str}. Priority: {parsed["priority"]}.'

    # Step 2: Draft response
    reply = call(step2_prompt)
    return reply

print(review_response_chain('Login is broken. App crashes on startup.'))

नेस्टेड JSON का सम्मिलन संभालना

जब चरण 1 नेस्टेड ऑब्जेक्ट लौटाए, तो प्रॉम्प्ट को संक्षिप्त रखने के लिए केवल वही निकालें जिसकी चरण 2 को आवश्यकता है:

step1_output = {
    'document': {
        'title': 'Q3 Report',
        'sections': [
            {'name': 'Revenue', 'value': '$4.2M', 'change': '+12%'},
            {'name': 'Users', 'value': '85,000', 'change': '+5%'},
            {'name': 'Churn', 'value': '3.2%', 'change': '-0.8%'}
        ]
    },
    'summary': 'Strong revenue quarter with moderate user growth.'
}

# Extract only what Step 2 needs — not the full nested object
def extract_for_step2(data):
    sections = data['document']['sections']
    metrics = '\n'.join(f"{s['name']}: {s['value']} ({s['change']})" for s in sections)
    return {
        'metrics': metrics,
        'summary': data['summary']
    }

step2_input = extract_for_step2(step1_output)
print(step2_input)

अत्यधिक सम्मिलन से बचना

एक सामान्य गलती चरण 1 के पूरे आउटपुट को चरण 2 में सम्मिलित करना है। इससे चरण 2 का प्रॉम्प्ट अनावश्यक रूप से बड़ा हो जाता है और अप्रासंगिक फ़ील्ड के कारण मॉडल भ्रमित हो सकता है।

  • खराब: f'Here is the analysis: {str(all_of_step1_output)}'
  • अच्छा: केवल वे विशिष्ट फ़ील्ड निकालें जिनकी चरण 2 को आवश्यकता है और उन्हें स्पष्ट लेबल के साथ सम्मिलित करें

चरण 2 को ठीक उतनी ही जानकारी मिलनी चाहिए जितनी उसे चाहिए — न अधिक, न कम।

आउटपुट के आधार पर सशर्त शाखाकरण

चरण 1 का पार्स किया हुआ आउटपुट यह नियंत्रित कर सकता है कि चरण 2 का कौन-सा प्रॉम्प्ट चले — इससे एक रैखिक शृंखला शाखाओं वाली पाइपलाइन में बदल जाती है:

def route_chain(user_message):
    # Step 1: Classify intent
    classification = json.loads(call(
        f'Classify this message as billing, technical, or general. Return JSON: {{"intent": str}}\n\nMessage: {user_message}'
    ))

    intent = classification['intent']

    # Route to specialized Step 2 prompt
    if intent == 'billing':
        prompt = f'You are a billing specialist. Address: {user_message}'
    elif intent == 'technical':
        prompt = f'You are a senior engineer. Provide technical guidance for: {user_message}'
    else:
        prompt = f'You are a general support agent. Respond to: {user_message}'

    return call(prompt)

print(route_chain('My invoice shows a wrong amount.'))

चरणों के बीच स्थिति संचित करना

लंबी शृंखलाओं के लिए, एक स्थिति शब्दकोश बनाए रखें जो प्रत्येक चरण के आउटपुट को संचित करता रहे:

def run_pipeline(initial_input):
    state = {'input': initial_input}

    # Step 1
    state['entities'] = json.loads(call(
        f'Extract entities as JSON: {{"people": [], "companies": []}}\n\n{state["input"]}'
    ))

    # Step 2 uses entities from Step 1
    companies_str = ', '.join(state['entities'].get('companies', []))
    state['company_types'] = call(
        f'Classify these companies as startup/enterprise: {companies_str}'
    )

    # Step 3 uses output from Steps 1 and 2
    state['summary'] = call(
        f'Write a 2-sentence summary.\nEntities: {state["entities"]}\nClassifications: {state["company_types"]}'
    )

    return state

result = run_pipeline('Apple and OpenAI announced a partnership with Elon Musk.')
print(result['summary'])

JSON निष्कर्षण उपयोगिताएँ

अपनी शृंखला के आधारभूत ढाँचे के लिए पुनः उपयोग योग्य निष्कर्षण उपयोगिता बनाएँ:

import re, json

def extract_json(text):
    "Extract JSON from model output, handling extra text around the object."
    # Try direct parse first
    try:
        return json.loads(text.strip())
    except json.JSONDecodeError:
        pass
    # Try finding JSON object by bracket matching
    start = text.find("{")
    end = text.rfind("}")
    if start != -1 and end != -1 and end > start:
        try:
            return json.loads(text[start:end+1])
        except json.JSONDecodeError:
            pass
    # Try finding JSON array
    start = text.find("[")
    end = text.rfind("]")
    if start != -1 and end != -1 and end > start:
        try:
            return json.loads(text[start:end+1])
        except json.JSONDecodeError:
            pass
    raise ValueError("Could not extract JSON from: " + text[:200])

print(extract_json('{"key": "value"}'))

आउटपुट-से-इनपुट प्रतिरूपों का परीक्षण

आउटपुट-से-इनपुट पाइपलाइन के लिए परीक्षण के दो स्तर आवश्यक हैं:

  • प्रत्येक चरण का इकाई परीक्षण: क्या चरण 1 भरोसेमंद ढंग से ऐसा JSON लौटाता है जिसे पार्स किया जा सके? क्या चरण 2 किसी दिए गए निकाले गए इनपुट के लिए सही आउटपुट तैयार करता है?
  • शृंखला का एकीकरण परीक्षण: क्या पूरी पाइपलाइन प्रतिनिधि इनपुट के लिए सही परिणाम देती है?

जहाँ एकरूपता महत्वपूर्ण हो, वहाँ वर्गीकरण और निष्कर्षण चरणों के लिए temperature=0 का उपयोग करके चरणों के प्रॉम्प्ट को नियतात्मक बनाए रखें।

def test_step1(review_text, expected_sentiment):
    raw = call(f'Analyze review. Return JSON: {{"sentiment": str}}\n\n{review_text}')
    parsed = extract_json(raw)
    assert parsed['sentiment'] == expected_sentiment, f'Expected {expected_sentiment}, got {parsed["sentiment"]}'
    print(f'PASS: sentiment={parsed["sentiment"]}')

# Run unit test for Step 1
test_step1('The product is excellent!', 'positive')
test_step1('This is terrible.', 'negative')

त्वरित जाँच

जब चरण 1 के परिणाम को प्रोग्राम के माध्यम से निकाला जाएगा और चरण 2 में सम्मिलित किया जाएगा, तब उसके लिए अनुशंसित आउटपुट प्रारूप क्या है?

आउटपुट-से-इनपुट — मुख्य निष्कर्ष

भरोसेमंद आउटपुट-से-इनपुट प्रतिरूप ही प्रॉम्प्ट शृंखलाओं को उत्पादन के लिए तैयार बनाते हैं:

  • चरण 1 के प्रॉम्प्ट को स्पष्ट स्कीमा वाले JSON लौटाने के लिए बनाएँ — गद्य नहीं
  • सम्मिलन से पहले चरण 1 के आउटपुट को पार्स करें: मार्कडाउन फ़ेंस हटाएँ और JSON को डिकोड करने की त्रुटि संभालें
  • केवल वे विशिष्ट फ़ील्ड सम्मिलित करें जिनकी चरण 2 को आवश्यकता है — अत्यधिक सम्मिलन से बचें
  • लंबी शृंखलाओं में डेटा संचित करने और आगे भेजने के लिए स्थिति शब्दकोशों का उपयोग करें
  • पार्स किया हुआ आउटपुट विशेष चरण 2 प्रॉम्प्ट तक पहुँचाने के लिए सशर्त शाखाकरण नियंत्रित कर सकता है
  • मॉडल आउटपुट की असंगतियों को संभालने वाली पुनः उपयोग योग्य JSON निष्कर्षण उपयोगिताएँ बनाएँ
  • प्रत्येक चरण का स्वतंत्र रूप से इकाई परीक्षण करें, फिर पूरी पाइपलाइन का एकीकरण परीक्षण करें
शुरुआत निःशुल्क

एआई शिक्षक के साथ AI प्रॉम्प्ट इंजीनियरिंग सीखें — निःशुल्क

अपने ब्राउज़र में वास्तविक कोड लिखें और चलाएँ, चौबीसों घंटे एआई शिक्षक से तुरंत सहायता पाएँ, और वेब या ऐप पर वहीं से शुरू करें जहाँ आपने छोड़ा था।

पाठ्यक्रम
53
पाठ
199

अक्सर पूछे जाने वाले प्रश्न

क्या “आउटपुट-से-इनपुट प्रारूप” पाठ निःशुल्क है?

हाँ — AI प्रॉम्प्ट इंजीनियरिंग अध्ययन पथ के 3 तक कोई भी पाठ, जिसमें “आउटपुट-से-इनपुट प्रारूप” भी शामिल है, यहाँ वेब पर पूरा पढ़ना निःशुल्क है। इसके बाद CoddyKit PRO हर पाठ अनलॉक करता है, साथ ही अंतर्निर्मित कोड संपादक और चौबीसों घंटे एआई शिक्षक के साथ इंटरैक्टिव अभ्यास भी उपलब्ध कराता है। AI प्रॉम्प्ट इंजीनियरिंग पाठ्यक्रम में कुल 4 पाठ शामिल हैं।

“आउटपुट-से-इनपुट प्रारूप” में मैं क्या सीखूँगा?

चरण 2 में डालने के लिए चरण 1 से संरचित डेटा निकालें। आप ब्राउज़र में सीधे चलाए जाने वाले व्यावहारिक कोड के साथ AI प्रॉम्प्ट इंजीनियरिंग का अभ्यास करते हैं, और पाठ पूरा करते समय 24/7 एआई ट्यूटर आपके प्रश्नों के उत्तर देता है।

क्या AI प्रॉम्प्ट इंजीनियरिंग शुरू करने के लिए मुझे किसी अनुभव की आवश्यकता है?

पहले के अनुभव की आवश्यकता नहीं है। CoddyKit पर AI प्रॉम्प्ट इंजीनियरिंग शुरुआती से लेकर उन्नत शिक्षार्थियों तक सभी के लिए व्यवस्थित किया गया है, इसलिए आप यहीं से या शुरुआत से सीखना शुरू कर सकते हैं और अपनी गति से आगे बढ़ सकते हैं। यह 4 में से 2वाँ पाठ है।

“आउटपुट-से-इनपुट प्रारूप” पाठ पूरा करने में कितना समय लगता है?

CoddyKit का अधिकांश पाठ लगभग 5–10 मिनट में पूरा हो जाता है। हर पाठ छोटा और संवादात्मक है, इसलिए आप लगातार प्रगति करते हैं और वेब या ऐप पर वहीं से सीखना जारी रख सकते हैं जहाँ आपने छोड़ा था।

क्या मैं इस AI प्रॉम्प्ट इंजीनियरिंग पाठ में कोड लिख और चला सकता हूँ?

हाँ। हर AI प्रॉम्प्ट इंजीनियरिंग पाठ में एक अंतर्निर्मित कोड संपादक शामिल है, जिससे आप सीधे अपने ब्राउज़र में वास्तविक कोड लिख और चला सकते हैं और तुरंत एआई प्रतिक्रिया पा सकते हैं—स्थानीय सेटअप की आवश्यकता नहीं है।

इस पाठ्यक्रम के सभी पाठ

  1. प्रॉम्प्ट चेनिंग क्या है?
  2. आउटपुट-से-इनपुट प्रारूप
  3. क्रमिक रूपांतरण चेन
  4. प्रॉम्प्ट चेन में त्रुटि सँभालना
← AI प्रॉम्प्ट इंजीनियरिंग पर वापस जाएँ