0Pricing
AI Prompt Engineering · レッスン

プロンプトから曖昧さを取り除く

指示が複数の解釈を許さないようにするためのテクニックを学びます。

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

曖昧さがAIに及ぼす影響

曖昧なプロンプトを受け取ると、モデルは複数の妥当な解釈から1つを選ばなければなりません。通常は最も一般的な解釈を選び、それが自分の選択であることを示さずに、自信を持って処理を進めます。

その結果、質問とは違う内容に対する、形式上は完全に整った回答が返ってきます。送信後に出力を書き直すよりも、送信前に曖昧さを認識して取り除くほうが効率的です。

定番:「もっと良くして」

「もっと良くして」は、おそらく存在する中で最も曖昧なプロンプトです。どう良くするのでしょうか。

  • 短くしますか?長くしますか?
  • よりフォーマルにしますか?よりカジュアルにしますか?
  • 例を増やしますか?減らしますか?
  • トーンを変えますか?構成を変えますか?
  • 文法を直しますか?語彙を変えますか?

モデルは1つの側面を選び、それを変更します。自分が変えてほしかった側面でなければ、書き直しのループから抜け出せなくなります。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

original_text = (
    'Our software helps companies manage their data. '
    'It has many features. Customers like it a lot.'
)

# Ambiguous improvement request
vague = f'Make this better:\n\n{original_text}'

# Unambiguous improvement request
specific = (
    f'Rewrite this product description to be exactly 50% shorter, '
    f'more confident in tone, and replace vague phrases like "many features" '
    f'and "a lot" with specific claims. Do not add new features I have not mentioned.\n\n'
    f'{original_text}'
)

for label, prompt in [('VAGUE', vague), ('SPECIFIC', specific)]:
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=200,
        messages=[{'role': 'user', 'content': prompt}]
    )
    print(f'--- {label} ---')
    print(response.content[0].text)
    print()

複数の解釈:実践例

指示対象が明確でない代名詞、相対的な形容詞、主語の欠落を含むプロンプトは、すべて曖昧である可能性があります。例を見てみましょう。

  • 「パフォーマンスを改善する」—何のパフォーマンスでしょうか?速度、精度、ユーザーエンゲージメントのどれでしょうか?
  • 「影響について書く」—肯定的な影響、否定的な影響、経済的な影響、社会的な影響のどれでしょうか?
  • 「これを修正する」—ロジック、スタイル、書式、文法のどれを修正するのでしょうか?
  • 「プロフェッショナルにする」—フォーマルな語彙にしますか?段落を構造化しますか?絵文字を削除しますか?
import openai

client = openai.OpenAI(api_key='sk-your-key-here')

# Disambiguating 'fix this code'
buggy_code = 'def divide(a, b): return a / b'

ambiguous = f'Fix this:\n{buggy_code}'

unambiguous = (
    f'Fix only the division-by-zero bug in this function. '
    f'Add a guard that raises a ValueError with message "b cannot be zero" when b=0. '
    f'Do not change anything else — keep the function signature and return type identical.\n\n'
    f'{buggy_code}'
)

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{'role': 'user', 'content': unambiguous}]
)
print(response.choices[0].message.content)

曖昧さを解消する方法:解釈を明示する

プロンプトが複数の方法で解釈される可能性があると分かっている場合は、どの解釈を求めているのかを明示してください。

テンプレート:「[曖昧な用語]と言うとき、私は[具体的な定義]を意味します。」

例:

  • 「編集すると言うとき、文法とスペルの修正だけを意味します。内容は変更しないでください。」
  • 「簡潔にと言うとき、最大3文を意味します。」
  • 「プロフェッショナルにと言うとき、一人称代名詞と短縮形を使わないことを意味します。」
import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=256,
    messages=[{
        'role': 'user',
        'content': (
            'Edit the following paragraph. '
            'When I say "edit", I mean: fix grammar and punctuation only. '
            'Do NOT change vocabulary, sentence structure, or content. '
            'When done, list each change you made in a numbered list below the edited text.\n\n'
            'The team have went to the meeting early, but the manager '
            'werent there so they waited for alot of time before leaving.'
        )
    }]
)
print(response.content[0].text)

曖昧さを解消する方法:範囲を定義する

改善や拡張を依頼するときは、対象範囲が曖昧になりがちです。何が対象で何が対象外なのかを正確に定義して解消してください。

対象範囲内:モデルが変更してよいもの
対象範囲外:変更せずに維持すべきもの

これは、意図しない変更が深刻な問題を引き起こす可能性があるコード編集、文書の改訂、データセット処理のタスクで特に重要です。

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

code_block = '''
def calculate_tax(income, rate):
    return income * rate

def calculate_net(income, tax):
    return income - tax
'''

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{
        'role': 'user',
        'content': (
            'Add Python type hints to the following code.\n'
            'IN SCOPE: adding type hints to parameters and return values only.\n'
            'OUT OF SCOPE: changing function names, logic, docstrings, or formatting.\n'
            'Do not add any comments or docstrings.\n\n'
            + code_block
        )
    }]
)
print(response.choices[0].message.content)

曖昧さを解消する方法:出力形式を指定する

特定の形式を求めているのに、それを伝えていないと、出力形式が曖昧になります。「データをください」—段落ですか?リストですか?表ですか?JSONオブジェクトですか?

期待する正確な出力形式を、必ず指定してください。明示的に伝えれば、モデルはその形式に正確に合わせます。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

candidates_text = (
    'Alice: 5 years Python, worked at Stripe, has a CS degree.\n'
    'Bob: 3 years JavaScript, worked at a startup, self-taught.\n'
    'Carol: 8 years Java, worked at Google, has an MS in CS.'
)

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=300,
    messages=[{
        'role': 'user',
        'content': (
            'Extract the candidate data below into a JSON array. '
            'Each object must have exactly these keys: name, years_experience, primary_language, '
            'previous_employer, education_level. '
            'education_level values: DEGREE, MASTERS, SELF_TAUGHT.\n\n'
            + candidates_text
        )
    }]
)
print(response.content[0].text)

曖昧さを解消する方法:モデルに確認させる

複雑で曖昧だと分かっているプロンプトを書くときは、タスクに取り組む前に確認質問をするようモデルに指示できます。

これはAIアシスタントを構築するときに特に役立ちます。優れた人間のコンサルタントと同じように、モデルに推測させるのではなく情報を集めさせたいからです。

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[
        {
            'role': 'system',
            'content': (
                'You are a professional copywriter. '
                'Before starting any writing task, ask exactly 3 clarifying questions '
                'that would most improve the output quality. '
                'Only proceed to write after the user answers those questions.'
            )
        },
        {
            'role': 'user',
            'content': 'Write a landing page headline for my business.'
        }
    ]
)
print(response.choices[0].message.content)

基準を設定する必要がある相対的な用語

相対的な用語には固定された意味がなく、人によって意味が異なります。

  • 「簡潔」—1文ですか?3文ですか?1段落ですか?
  • 「フォーマル」—短縮形を使わないことですか?学術的な引用形式ですか?法律用語ですか?
  • 「簡単」—小学5年生程度の読解レベルですか?技術用語を使わないことですか?短い文だけにすることですか?
  • 「包括的」—主要なケースをすべて扱うことですか?エッジケースも含めることですか?例を付けることですか?

相対的な用語はすべて、具体的で測定可能な表現に置き換えてください。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

# Relative terms mapped to concrete equivalents
mapping = [
    ('Give me a brief summary',   'Summarize in exactly 2 sentences'),
    ('Write something formal',    'Write using no contractions, no first person, and Flesch-Kincaid grade 12+'),
    ('Make it simple',            'Use only words a 10-year-old would know; max 15 words per sentence'),
    ('Be comprehensive',          'Cover at least 5 distinct subtopics with one example each'),
]

for vague, concrete in mapping:
    print(f'Vague:    "{vague}"')
    print(f'Concrete: "{concrete}"')
    print()

主語の曖昧さ:行為を実行するのは誰か

主語の曖昧さは、指示の対象が誰なのか、または何なのかが不明確なときに起こります。

「導入部を書き直してください」—何の導入部でしょうか?貼り付けた文書ですか?5ターン前に話し合った文書ですか?新しい文書ですか?

「これを翻訳してください」—どの部分でしょうか?回答全体ですか?要約のセクションだけですか?コードコメントですか?

特に複数ターンの会話では、意図する具体的な対象やセクションを必ず明示してください。

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

# Clear subject reference prevents wrong-section edits
contract_text = (
    '## Section 1: Payment Terms\nPayment is due within 30 days.\n\n'
    '## Section 2: Termination\nEither party may terminate with 30 days notice.'
)

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{
        'role': 'user',
        'content': (
            'In the contract below, rewrite ONLY Section 2 (Termination). '
            'Change the notice period from 30 days to 90 days. '
            'Do not change Section 1 or any other text.\n\n'
            + contract_text
        )
    }]
)
print(response.choices[0].message.content)

時間の曖昧さ:いつか

プロンプト内の時間に関する表現は曖昧になることがあります。「最近の」「現在の」「最新の」「今」などです。

モデルの学習データにはカットオフ日があるため、伝えない限り「今」が何を意味するのか分かりません。時間に敏感なタスクでは、必ず具体的な日付を指定してください。

  • 「最近の研究」→「2024年または2025年に発表された研究」
  • 「現在のベストプラクティス」→「2025年1月時点のベストプラクティス」
  • 「最新バージョン」→「バージョン3.12(2024年10月リリース)」
import anthropic
from datetime import date

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

today = date.today().isoformat()

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=256,
    system=f'Today is {today}. Use this as the reference for any time-related words.',
    messages=[{
        'role': 'user',
        'content': (
            'Describe the best practices for Python async programming '
            'as of January 2025. If your knowledge does not cover this timeframe, '
            'say so explicitly and share what you know up to your cutoff.'
        )
    }]
)
print(response.content[0].text)

曖昧さレーダーを作る

プロンプトを送信する前に、次の曖昧さの兆候がないか確認してください。

  • 指示対象が明確でない代名詞:it、this、that、they
  • 相対的な形容詞:より良い、より短い、フォーマルな、簡単な、包括的な、最近の
  • 曖昧な動詞:修正する、改善する、更新する、作る、何かに対処する
  • 対象範囲の欠落:対象範囲内と対象範囲外の記載がない
  • 形式の欠落:出力形式が指定されていない
  • 文脈の欠落:対象読者が誰か、出力の用途が何かが不明
def scan_prompt_for_ambiguity(prompt):
    '''Simple heuristic scanner for common ambiguity patterns.'''
    warnings = []
    vague_verbs = ['fix', 'improve', 'make it', 'update', 'change it', 'redo']
    relative_adj = ['better', 'shorter', 'longer', 'formal', 'simple', 'recent', 'comprehensive']
    missing_format = ['json', 'table', 'list', 'bullet', 'paragraph', 'word', 'sentence']

    lower = prompt.lower()
    for v in vague_verbs:
        if v in lower:
            warnings.append(f'Vague verb detected: "{v}" — specify what change exactly')
    for a in relative_adj:
        if a in lower:
            warnings.append(f'Relative adjective: "{a}" — anchor with a measurable definition')
    if not any(f in lower for f in missing_format):
        warnings.append('No output format specified — add format, length, or structure')
    return warnings

test = 'Make the report better and more formal.'
print('Prompt:', test)
for w in scan_prompt_for_ambiguity(test):
    print(' WARNING:', w)

理解度チェック

ある開発者が「コードを簡単にしてください」というプロンプトを送信しました。AIはコードを短くしましたが、開発者が望んでいたのはコードを短くすることではなく、より読みやすい変数名を使うことでした。核心的な問題は何でしたか?

曖昧さを取り除く — まとめ

曖昧さがあると、モデルは推測しなければなりません。そしてその推測は、あなたの意図ではなく、最も平均的な解釈になります。曖昧さを解消する主な方法は次のとおりです。

  • 解釈を明示する:「Xと言うとき、Yを意味します」
  • 範囲を定義する:対象範囲内と対象範囲外を列挙する
  • 出力形式を明示する:JSON/表/段落/文数
  • 相対的な用語に基準を設定する:「簡潔」→「2文」、「フォーマル」→「短縮形を使わない」
  • 主語を明示する:「この部分」ではなく「セクション2」
  • 確認を求める:続行する前に質問するようモデルに指示する

よくある質問

「プロンプトから曖昧さを取り除く」レッスンは無料ですか?

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

「プロンプトから曖昧さを取り除く」で何を学びますか?

指示が複数の解釈を許さないようにするためのテクニックを学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「プロンプトから曖昧さを取り除く」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. 具体性が重要な理由
  2. プロンプトから曖昧さを取り除く
  3. 具体的な詳細を加える
  4. 曖昧なプロンプトと具体的なプロンプトの比較
← AI Prompt Engineeringに戻る