While these tips apply broadly to all Claude models, you can find prompting tips specific to extended thinking models here.
Prefilling hanya tersedia untuk mode non-extended thinking. Saat ini tidak didukung dengan extended thinking.
Assistant. Teknik yang kuat ini memungkinkan Anda mengarahkan tindakan Claude, melewati pembukaan, menerapkan format spesifik seperti JSON atau XML, dan bahkan membantu Claude mempertahankan konsistensi karakter dalam skenario role-play.
Dalam beberapa kasus di mana Claude tidak berkinerja seperti yang diharapkan, beberapa kalimat yang di-prefill dapat sangat meningkatkan performa Claude. Sedikit prefilling dapat memberikan dampak yang besar!
Cara melakukan prefill respons Claude
Untuk melakukan prefill, sertakan teks awal yang diinginkan dalam pesanAssistant (respons Claude akan berlanjut dari tempat pesan Assistant berakhir):
Konten prefill tidak boleh diakhiri dengan spasi kosong. Prefill seperti
"As an AI assistant, I " (dengan spasi di akhir) akan menghasilkan error.Contoh
Contoh 1: Mengontrol format output dan melewati pembukaan
Tips pengguna mahir: Prefilling
{ memaksa Claude untuk melewati pembukaan dan langsung mengeluarkan objek JSON. Ini lebih bersih, lebih ringkas, dan lebih mudah untuk diparse oleh program tanpa pemrosesan tambahan.Contoh: Ekstraksi data terstruktur tanpa prefilling
Contoh: Ekstraksi data terstruktur tanpa prefilling
| Role | Content |
|---|---|
| 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! |
Contoh: Ekstraksi data terstruktur dengan prefilling
Contoh: Ekstraksi data terstruktur dengan prefilling
| Role | Content |
|---|---|
| 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 (prefill) | { |
| Assistant (Claude’s response) | “name”: “SmartHome Mini”, “size”: “5 inches wide”, “price”: “$49.99”, “colors”: [ “black”, “white” ] } |
Contoh 2: Mempertahankan karakter dalam skenario roleplay
Tips role-play: Prefilling
[ROLE_NAME] dalam kurung siku dapat mengingatkan Claude untuk tetap dalam karakter, bahkan untuk percakapan yang lebih panjang dan kompleks. Ini sangat kuat ketika dikombinasikan dengan role prompting dalam parameter system.Contoh: Mempertahankan karakter tanpa role prompting
Contoh: Mempertahankan karakter tanpa role prompting
| Role | Content |
|---|---|
| User (50 giliran percakapan dengan Claude “Sherlock Holmes”) | 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… |
Contoh: Mempertahankan karakter dengan role prompting
Contoh: Mempertahankan karakter dengan role prompting
| Role | Content |
|---|---|
| User (50 giliran percakapan dengan Claude “Sherlock Holmes”) | What do you deduce about the owner of this shoe? <image>muddy_shoe.jpg</image> |
| Assistant (prefill) | [Sherlock Holmes] |
| Assistant (Claude’s response) | 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! |
Perpustakaan prompt
Dapatkan inspirasi dari koleksi prompt yang dikurasi untuk berbagai tugas dan kasus penggunaan.
Tutorial prompting GitHub
Tutorial yang dipenuhi contoh yang mencakup konsep prompt engineering yang ditemukan dalam dokumentasi kami.
Tutorial prompting Google Sheets
Versi yang lebih ringan dari tutorial prompt engineering kami melalui spreadsheet interaktif.