プロンプトエンジニアリング
Claudeの応答を事前入力してより良い出力制御を実現する
While these tips apply broadly to all Claude models, you can find prompting tips specific to extended thinking models here.
事前入力は拡張思考モード以外でのみ利用可能です。現在、拡張思考では対応していません。
Claudeを使用する際、Assistant
メッセージを事前入力することで応答を誘導するユニークな機能があります。この強力なテクニックを使用すると、Claudeの行動を指示したり、前置きをスキップしたり、JSONやXMLなどの特定のフォーマットを強制したり、さらにはロールプレイシナリオでClaudeのキャラクター一貫性を維持するのに役立ちます。
Claudeが期待通りに動作していないケースでは、数文の事前入力がClaudeのパフォーマンスを大幅に向上させることがあります。少しの事前入力が大きな効果をもたらします!
Claudeの応答を事前入力する方法
事前入力するには、Assistant
メッセージに希望する初期テキストを含めます(Claudeの応答はAssistant
メッセージの終わりから続きます):
事前入力の内容は末尾に空白を含めることができません。"As an AI assistant, I "
(末尾にスペースがある)のような事前入力はエラーになります。
例
例1:出力フォーマットの制御と前置きのスキップ
パワーユーザーのヒント:
{
を事前入力すると、Claudeは前置きをスキップしてJSONオブジェクトを直接出力するよう強制されます。これにより、より簡潔でプログラムが追加処理なしで解析しやすい出力が得られます。例:事前入力なしの構造化データ抽出
例:事前入力なしの構造化データ抽出
役割 | 内容 |
---|---|
User | Extract the name, size, price, and color from this product description as a JSON object: <description> The SmartHome Mini is a compact smart home assistant available in black or white for only $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other connected devices via voice or app—no matter where you place it in your home. This affordable little hub brings convenient hands-free control to your smart devices. </description> |
Assistant | Here’s the extracted information in JSON format: ```json { “name”: “SmartHome Mini”, “size”: “5 inches wide”, “price”: “$49.99”, “colors”: [“black”, “white”] } ``` I’ve extracted the following details from the product description: - Name: SmartHome Mini - Size: 5 inches wide - Price: $49.99 - Colors: Available in black and white The JSON object provides a structured format that’s easy for programs to parse and use. Let me know if you need any modifications or have any other questions! |
例:事前入力を使用した構造化データ抽出
例:事前入力を使用した構造化データ抽出
役割 | 内容 |
---|---|
User | Extract the name, size, price, and color from this product description as a JSON object: <description> The SmartHome Mini is a compact smart home assistant available in black or white for only $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other connected devices via voice or app—no matter where you place it in your home. This affordable little hub brings convenient hands-free control to your smart devices. </description> |
Assistant (事前入力) | { |
Assistant (Claudeの応答) | “name”: “SmartHome Mini”, “size”: “5 inches wide”, “price”: “$49.99”, “colors”: [ “black”, “white” ] } |
例2:ロールプレイシナリオでのキャラクター維持
ロールプレイのヒント:角括弧で囲んだ
[ROLE_NAME]
を事前入力すると、より長く複雑な会話でもClaudeがキャラクターを維持するのに役立ちます。これはsystem
パラメータでのロールプロンプトと組み合わせると特に効果的です。例:ロールプロンプトなしでのキャラクター維持
例:ロールプロンプトなしでのキャラクター維持
役割 | 内容 |
---|---|
User (「シャーロック・ホームズ」Claudeとの50ターンの会話中) | What do you deduce about the owner of this shoe? <image>muddy_shoe.jpg</image> |
Assistant | As an AI assistant, I would be happy to analyze the image of a muddy shoe as if you had provided it. Here’s my deduction… |
例:ロールプロンプトを使用したキャラクター維持
例:ロールプロンプトを使用したキャラクター維持
役割 | 内容 |
---|---|
User (「シャーロック・ホームズ」Claudeとの50ターンの会話中) | What do you deduce about the owner of this shoe? <image>muddy_shoe.jpg</image> |
Assistant (事前入力) | [Sherlock Holmes] |
Assistant (Claudeの応答) | Ah, what have we here? A most curious specimen, Watson! Let us examine this shoe with a discerning eye. The mud, you see, is not your common London clay, but rather the distinctive reddish hue of the iron-rich soil found only in the environs of Hampstead Heath. And yet, the wear on the sole suggests a gait more suited to the cobblestones of Whitechapel than the gentle slopes of the Heath. Now, observe the laces! They are tied with a particular knot favored by those in the medical profession—doubtless a habit acquired during years of tying surgical gowns. But the scuff marks on the toe box tell a different tale: they are consistent with the kicking motion one might employ in the martial arts, specifically Baritsu. We may conclude, then, that our absent shoe owner is a doctor, possibly a surgeon, who resides in Whitechapel but frequents Hampstead Heath—perhaps for a secret Baritsu practice, away from prying eyes. A most intriguing case, Watson! We must make haste; the game is afoot! |