0Pricing
AI Prompt Engineering · レッスン

メタプロンプティングとは

別のプロンプトを生成するプロンプト:LLMが持つ再帰的な力を学びます。

「メタプロンプティングとは」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。

メタプロンプティングの定義

メタプロンプティングとは、出力として別のプロンプトを生成するプロンプトを書く方法です。タスクを直接解決するのではなく、メタプロンプトによって、タスクを解決するための指示をモデルに生成させます。通常のプロンプティングよりも一段上の抽象化レイヤーです。

一次プロンプティングとメタプロンプティング

一次プロンプティングとメタプロンプティングの違いは次のとおりです。一次プロンプトは、要約、コード、分析などのタスクの出力を生成します。メタプロンプトは、実際のタスクに適用できるプロンプト、評価基準、システム指示を生成します。

import anthropic

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

# FIRST-ORDER prompt (produces a task output directly)
first_order = 'Write a customer service response for a user whose order was delayed.'

# META-PROMPT (produces a prompt that can then solve similar tasks)
meta_prompt = (
    'Design a system prompt for a customer service AI agent '
    'that handles order delay complaints. The agent should '
    'be empathetic, solution-focused, and proactively offer '
    'compensation when appropriate. Output only the system prompt.'
)

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

ユースケース1:システムプロンプトの生成

メタプロンプティングの最も強力な用途の1つは、特定の役割やアプリケーション向けのシステムプロンプトを生成することです。システムプロンプトを手作業で作成する代わりに、用途の説明を与えて、モデルにシステムプロンプトを作成させます。

META_SYSTEM_PROMPT_GENERATOR = '''You are a prompt engineer specializing in system prompts.
Given a description of an AI assistant role, generate a comprehensive system prompt.

The system prompt you generate must:
1. Define the assistant\'s persona and expertise
2. Specify its primary objectives
3. List behavioral rules (what it should and should not do)
4. Define output format preferences
5. Include appropriate disclaimers for the domain
6. Be between 200-400 words

Output only the system prompt — no explanation, no preamble.'''

def generate_system_prompt(role_description):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=600,
        system=META_SYSTEM_PROMPT_GENERATOR,
        messages=[{'role': 'user', 'content':
            f'Generate a system prompt for: {role_description}'}]
    )
    return response.content[0].text

# Example: generate a system prompt for a coding tutor
result = generate_system_prompt(
    'A Python coding tutor for absolute beginners aged 12-16, '
    'who explains concepts using simple analogies and emojis'
)
print(result[:400], '...')

ユースケース2:評価基準の作成

メタプロンプティングを使うと、タスクの評価基準を生成できます。「良い」状態とは何かを手作業で定義する代わりに、目的に応じた評価基準をモデルに生成させます。

META_CRITERIA_GENERATOR = '''You are an evaluation framework designer.
Given a task description, create a detailed evaluation rubric.

For each criterion:
- Name: concise label
- Weight: percentage (all weights sum to 100)
- Description: what to look for
- Scoring: 1-5 scale with what each score means

Output as a JSON array.'''

def generate_eval_criteria(task_description):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1000,
        system=META_CRITERIA_GENERATOR,
        messages=[{'role': 'user', 'content':
            f'Create evaluation criteria for: {task_description}'}]
    )
    return json.loads(response.content[0].text)

criteria = generate_eval_criteria(
    'AI-generated summaries of financial earnings reports'
)
for c in criteria[:3]:
    print(f'{c["name"]} ({c["weight"]}%): {c["description"][:50]}')

ユースケース3:プロンプトテンプレートの設計

メタプロンプティングを使うと、一般的なタスク向けの再利用可能なプロンプトテンプレートを生成できます。メタプロンプトにタスクの説明を与えると、{variable}プレースホルダーを含むパラメーター化されたテンプレートが出力されます。

META_TEMPLATE_DESIGNER = '''You are a prompt template engineer.
Given a task type, design a prompt template with {variable} placeholders.

Requirements:
- Identify all input variables and use {variable_name} syntax
- Include clear instruction structure
- Specify desired output format
- Add any necessary constraints or rules
- Output: JSON with keys: template (string), variables (list of variable descriptions)'''

def design_prompt_template(task_type):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=800,
        system=META_TEMPLATE_DESIGNER,
        messages=[{'role': 'user', 'content':
            f'Design a prompt template for: {task_type}'}]
    )
    return json.loads(response.content[0].text)

template = design_prompt_template('extracting action items from meeting notes')
print('Template:', template['template'][:200], '...')
print('Variables:', template['variables'][:3])

ペルソナ生成のためのメタプロンプティング

メタプロンプティングを使うと、多様なAIペルソナの定義を生成できます。これは、ロールプレイアプリケーション、チャットボットの設定、異なるペルソナにおけるAIの動作テストに役立ちます。

META_PERSONA_GENERATOR = '''Generate {num_personas} distinct AI assistant personas for the following application.
Each persona should have:
- Name
- Personality traits (3-5 adjectives)
- Communication style description
- Expertise areas
- Signature phrases or patterns
- Things this persona would never say

Make personas meaningfully different from each other.
Output as a JSON array.'''

def generate_personas(application, num_personas=3):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1500,
        messages=[{'role': 'user', 'content':
            META_PERSONA_GENERATOR.format(num_personas=num_personas) +
            f'\n\nApplication: {application}'}]
    )
    return json.loads(response.content[0].text)

personas = generate_personas('a fitness and wellness coaching app')
for p in personas:
    print(f'{p["name"]}: {p["personality_traits"]}')

メタプロンプトのチェーン

メタプロンプティングは、チェーン化すると最も強力になります。1つのメタプロンプトの出力を次のメタプロンプトに入力するのです。これにより、高レベルの要件から高度なAIシステムを構築できるプロンプト生成パイプラインが作られます。

def meta_prompt_pipeline(application_description):
    print('Step 1: Generating system prompt...')
    system_prompt = generate_system_prompt(application_description)

    print('Step 2: Generating evaluation criteria...')
    criteria = generate_eval_criteria(
        f'Responses from an AI assistant that: {application_description}'
    )

    print('Step 3: Generating test cases...')
    test_cases_meta = (
        f'Generate 5 diverse test user messages for an AI assistant '
        f'that {application_description}. '
        f'Include edge cases and difficult requests. Return as JSON list.'
    )
    test_response = client.messages.create(
        model='claude-opus-4-5', max_tokens=800,
        messages=[{'role': 'user', 'content': test_cases_meta}]
    )
    import json
    test_cases = json.loads(test_response.content[0].text)

    return {
        'system_prompt': system_prompt,
        'eval_criteria': criteria,
        'test_cases': test_cases
    }

result = meta_prompt_pipeline('helps junior developers understand error messages')
print('Pipeline output keys:', list(result.keys()))

メタプロンプトの品質管理

生成されたプロンプトは、使用する前に検証する必要があります。必要な要素がすべて含まれているか、よくある落とし穴を避けているかを確認してください。自動チェックとレビューの工程を取り入れましょう。

def validate_generated_system_prompt(system_prompt):
    checks = {
        'Has persona definition': any(w in system_prompt.lower() for w in
            ['you are', 'your role', 'you\'re', 'act as']),
        'Has behavioral rules': any(w in system_prompt.lower() for w in
            ['do not', 'never', 'always', 'must', 'should']),
        'Has output format': any(w in system_prompt.lower() for w in
            ['format', 'output', 'structure', 'respond with']),
        'Length appropriate': 100 < len(system_prompt.split()) < 600,
        'No explicit profanity': True,  # add real check in production
        'Has domain scope': len(system_prompt) > 50
    }
    passed = sum(checks.values())
    print(f'Validation: {passed}/{len(checks)} checks passed')
    for check, result in checks.items():
        status = 'PASS' if result else 'FAIL'
        print(f'  [{status}] {check}')
    return all(checks.values())

# Validate a generated prompt
test_prompt = 'You are a helpful customer service assistant. Always be polite.'
validate_generated_system_prompt(test_prompt)

メタプロンプティングの制限

メタプロンプティングは強力ですが、実務で使う人が理解しておくべき重要な制限もあります。生成されたプロンプトは、本番環境で使う前に人間がレビューする必要があります。

meta_prompting_limitations = {
    'Quality variance': (
        'Generated prompts vary in quality. '
        'Always evaluate and iterate — do not use raw output in production.'
    ),
    'Domain knowledge gaps': (
        'The model may generate plausible-sounding prompts that '
        'miss critical domain-specific requirements. '
        'Domain experts must review generated criteria and rules.'
    ),
    'Hallucinated instructions': (
        'Generated prompts may include instructions that sound right '
        'but are incorrect (e.g., citing wrong regulations, wrong APIs). '
        'Verify all factual claims in generated prompts.'
    ),
    'Misalignment with intent': (
        'A generated system prompt may technically fulfill the meta-prompt '
        'but not capture the actual product requirements. '
        'User testing is still required.'
    ),
    'Compounding errors': (
        'In meta-prompt chains, errors in early stages compound. '
        'Validate outputs at each step before passing to the next.'
    )
}

for limitation, description in meta_prompting_limitations.items():
    print(f'{limitation}: {description[:80]}...')

プロンプト批評のためのメタプロンプティング

メタプロンプティングは、プロンプトの生成だけでなく、既存のプロンプトの批評にも使えます。モデルにプロンプトをレビューさせ、不足している制約、曖昧な指示、出力形式の仕様不足などの弱点を特定させます。

CRITIQUE_META_PROMPT = '''You are an expert prompt engineer.
Review the following prompt and identify weaknesses.

Prompt to review:
{prompt_to_review}

For each weakness:
1. Weakness: what is missing or unclear
2. Impact: what problems this causes in practice
3. Fix: exact suggested replacement text

Also provide:
- Overall quality score: 1-10
- Top 3 improvements ordered by impact

Be specific — quote the relevant part of the prompt.'''

def critique_existing_prompt(prompt_text):
    import anthropic
    client = anthropic.Anthropic(api_key='YOUR_API_KEY')
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1000,
        messages=[{'role': 'user', 'content':
            CRITIQUE_META_PROMPT.format(prompt_to_review=prompt_text)}]
    )
    return response.content[0].text

# Example usage
weak_prompt = 'Summarize the article.'
critique = critique_existing_prompt(weak_prompt)
print(critique[:300], '...')

メタプロンプティングと手動のプロンプトエンジニアリング

メタプロンプティングと手動のプロンプトエンジニアリングには、それぞれ異なる強みがあります。どのように使うかだけでなく、いつ使うかを理解することも重要です。

WHEN_TO_USE = {
    'Meta-prompting is better when': [
        'You need many prompt variants quickly (A/B testing)',
        'The use case is well-defined and the requirements are clear',
        'You need to scale prompt creation across many categories',
        'You want to explore the design space of possible prompts',
        'You have evaluation criteria to filter generated prompts'
    ],
    'Manual prompt engineering is better when': [
        'Deep domain expertise is required (medical, legal, safety-critical)',
        'The prompt controls a high-stakes production system',
        'Iterative refinement and human judgment are essential',
        'The requirements are nuanced and hard to express to a meta-prompt',
        'You need guaranteed correctness (not just plausible)'
    ]
}

for mode, reasons in WHEN_TO_USE.items():
    print(f'\n{mode}:')
    for r in reasons[:3]:
        print(f'  - {r}')

確認問題

メタプロンプトと通常のプロンプトを区別する決定的な特徴は何でしょうか。

メタプロンプティングのまとめ

メタプロンプティングは、プロンプトエンジニアリングに強力な抽象化レイヤーを加えます。

  • 定義:出力として別のプロンプトを生成するプロンプト
  • ユースケース:システムプロンプトの生成、評価基準の作成、テンプレート設計、ペルソナ生成
  • メタプロンプトのチェーン:メタプロンプトを連結して、AIアプリケーションの設定全体を構築します
  • 品質管理:生成されたプロンプトは、本番環境で使う前に必ず検証します
  • 制限:ドメイン知識の不足、誤った指示の生成、チェーンによるエラーの連鎖
  • 適した用途:プロンプト作成の拡張、設計空間の探索、テストスイートの生成

よくある質問

「メタプロンプティングとは」レッスンは無料ですか?

はい。「メタプロンプティングとは」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。

「メタプロンプティングとは」で何を学びますか?

別のプロンプトを生成するプロンプト:LLMが持つ再帰的な力を学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

AI Prompt Engineeringを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「メタプロンプティングとは」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAI Prompt Engineeringレッスンでコードを書いて実行できますか?

はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. メタプロンプティングとは
  2. プロンプトを生成するプロンプト
  3. 自己改善型プロンプトシステム
  4. 自己改善における評価と選択
← AI Prompt Engineeringに戻る