19P by ninebow 2달전 | favorite | 댓글과 토론

들어가며

작년 중순쯤 OpenAI에서 ChatGPT 모델을 사용하며 더 나은 답변을 얻기 위한 프롬프트 작성 전략 6가지를 번역 및 정리한 적이 있었는데요, 최근 Claude-3도 본격적으로 사용을 시작하면서 찾아보니 미묘하게 예시 프롬프트들이 느낌이 다른 것을 발견하게 되었습니다.

뭔가 다른 점이 있나하고 참고할 자료를 찾아보다가 Anthropic에서 공개한 프롬프트 엔지니어링 문서가 있길래 대략 읽어보았는데, OpenAI에서 정리했던 6가지 프롬프트 작성 전략과 겹치는 부분이 많아보여서 전문을 다 정리하기 보다는 경쟁 모델(...)인 ChatGPT에게 간략히 정리를 요청해봤습니다.

한 번 살펴보시고, 부족한 내용은 OpenAI의 GPT 모범 사례: 개요. 더 나은 답변을 얻기 위한 6가지 프롬프트 작성 전략 (Six strategies for getting better results) 시리즈와 함께 Anthropic의 원문을 살펴봐주세요. :D

소개

이번 문서는 Claude-3의 프롬프트 엔지니어링 전략에 대해 다루고 있습니다. 이러한 전략들을 사용하여 Claude-3의 성능을 향상시키고 특정 사용 사례에 맞게 응답을 미세 조정할 수 있습니다. 이러한 기술은 필수적이지 않지만 Claude의 입력과 출력을 개선하는데 도움을 줄 수 있습니다.

프롬프트 엔지니어링은 실험 과학으로, 프롬프트를 반복하고 테스트하여 성능을 최적화하는 과정을 포함합니다. 즉, 프롬프트 엔지니어링은 이는 엔티티 추출, 질문 응답, 텍스트 요약에서 복잡한 작업으로 이어지는 반복적인 개발과 평가를 통해 진행되며, 이 과정에서 다양한 테스트 케이스를 생성하고, 초기 프롬프트를 개발하여 모델의 반응을 평가하고 수정하는 단계를 포함합니다.

Claude와 다른 AI 모델들과의 비교를 통해, Claude-3은 특정 역할을 부여받거나 XML 태그를 사용하는 등의 다양한 프롬프트 공학 기술을 사용하여 성능을 향상시킬 수 있다는 점에서 차별화됩니다. 이러한 기술들은 Claude가 더 정확하고 일관된 출력을 제공하도록 도와줍니다.

주요 기법들

다음은 문서에 설명하고 있는 주요 기법들입니다:

명확하고 직접적으로 묻기(Be clear & direct

Claude에게 원하는 응답을 알려주기 위기 위해 명확한 지침과 맥락을 제공하세요:

  1. 자세한 맥락과 지시 제공: 작업을 정확하게 수행하기 위해 Claude에게 가능한 한 많은 맥락과 상세한 지시를 제공해야 합니다. 예를 들어, 개인정보를 제거해달라는 요청에서 구체적으로 어떤 정보를 어떻게 제거해야 하는지 명확히 지시하는 것이 포함됩니다.

|Role|Prompt|
| --- | --- |
|User|We want to anonymize some text by removing all personally identifiable information (PII). <br /><br />Please follow these steps:<br />1. Replace all instances of names, phone numbers, and home and email addresses with 'XXX'.<br />2. If the text contains no PII, copy it word-for-word without replacing anything.<br />3. Output only the processed text, without any additional commentary.<br /><br />Here is the text to process:<br />{{TEXT}}|

  1. 번호 목록 또는 글머리 기호 사용: 복잡한 작업 지시 시 번호 목록이나 글머리 기호를 사용하여 지시를 구분하면 Claude가 지시를 더 잘 이해하고 따를 수 있습니다. 예를 들어, 교과서 장을 교육 계획으로 전환하라는 지시에서 각 단계를 명확하게 분리하여 지시할 수 있습니다.

|Role|Prompt|
| --- | --- |
|User|Your task is turn the given textbook chapter into a comprehensive lesson plan. To do this task, you should:<br />1. Extract and summarize key concepts by section<br />2. Convert each extracted concept into a 30 minute lesson plan, including a list of questions to check comprehension.<br />3. Design an accompanying homework assignment that reinforces learnings from this chapter.<br /><br />Here is the chapter:<br /><chapter><br />{{CHAPTER}}<br /></chapter>|

  1. 원하는 것을 구체적으로 명시: Claude에게 명확한 대답이나 특정한 입장을 요구할 때 이를 명시적으로 밝혀야 합니다. 예를 들어, "역대 최고의 농구 선수가 누구인가?"라는 질문에, 구체적으로 하나의 선수를 선택하도록 요구할 수 있습니다.

|Role|Prompt|
|---|---|
|User|(안 좋은 예) Who is the best basketball player of all time?<br /> (좋은 예) Who is the best basketball player of all time? Yes, there are differing opinions, but if you absolutely had to pick one player, who would it be?|
|Assistant (Claude's response)|There is no definitive answer to who is the best basketball player of all time, as reasonable people can disagree on this. However, if forced to choose just one player, I would say Michael Jordan is most commonly considered the GOAT (Greatest Of All Time) based on his exceptional talent, championships, awards, and cultural impact on the game of basketball. But others like LeBron James, Kareem Abdul-Jabbar, Wilt Chamberlain and Bill Russell are also frequently mentioned in the debate. It's a subjective call without a clear consensus.|

  1. 명확한 프롬프팅의 황금률: 프롬프트를 다른 사람에게 보여주고 그 지시대로 실행할 수 있는지 확인하십시오. 이는 Claude에게도 마찬가지로 적용되어, 지시가 명확한지 검증하는 데 도움이 됩니다.

예시 제공하기 (Use examples

원하는 출력 형식이나 스타일을 설명하기 위해 프롬프트에 예시를 포함하세요.

  1. 왜 예시를 사용하는가?: 예시를 사용하면 Claude가 주어진 지시를 더 잘 이해하고 원하는 출력 형식을 명확하게 파악할 수 있습니다. 이를 통해 모델이 더 정확하고 일관된 결과를 생성하도록 도울 수 있습니다.

  2. 효과적인 예시 만들기: 효과적인 예시는 입력과 예상 출력을 명확하게 보여줘야 합니다. 예시는 실제 사용 사례를 반영해야 하며, Claude가 학습할 수 있는 충분한 정보를 포함해야 합니다.

|Role|Content|
| --- | --- |
|User|I will give you some quotes. Please extract the author from the quote block.<br /><br />Here is an example:<br /><example><br />Quote:<br />"When the reasoning mind is forced to confront the impossible again and again, it has no choice but to adapt."<br />― N.K. Jemisin, The Fifth Season<br />Author: N.K. Jemisin<br /></example><br /><br />Quote:<br />"Some humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard."<br />― Ted Chiang, Exhalation<br />Author:|
|Assistant<br />(Claude's response)|Ted Chiang|

  1. 출력 형식화: 예시를 사용하여 원하는 출력 형식을 지정함으로써, Claude가 결과를 예측 가능하고 일관된 방식으로 제공할 수 있도록 합니다. 이는 특히 데이터 추출이나 보고서 생성과 같은 작업에서 유용합니다.

|Role|Content|
| --- | --- |
|User|<example><br />Text: Sarah Martinez, a dedicated nurse, was known for her compassionate care at the local hospital. David Thompson, an innovative software engineer, worked tirelessly on groundbreaking projects.<br />Output:<br />1. Sarah Martinez [NURSE]<br />2. David Thompson [SOFTWARE ENGINEER]<br /></example><br /><br /><example><br />Text: Chef Oliver Hamilton has transformed the culinary scene with his farm-to-table restaurant. Just down the street, you'll find the library, where head librarian Elizabeth Chen has worked diligently to create a welcoming space for all.<br />Output:<br />1. Oliver Hamilton [CHEF]<br />2. Elizabeth Chen [LIBRARIAN]<br /></example><br /><br />Text: At the town's bustling farmer's market, you'll find Laura Simmons, a passionate organic farmer known for her delicious produce. In the community center, Kevin Alvarez, a skilled dance instructor, has brought the joy of movement to people of all ages.<br />Output:|
|Assistant (Claude's response)|1. Laura Simmons [ORGANIC FARMER]<br />2. Kevin Alvarez [DANCE INSTRUCTOR]|

  1. 주의 사항: 예시를 사용할 때는 너무 한정된 데이터에 의존하지 않도록 주의해야 하며, Claude가 특정 패턴에만 과도하게 의존하는 것을 방지해야 합니다.

  2. 반복 및 수정: 처음 제공한 예시로 원하는 결과를 얻지 못했다면, 예시를 수정하거나 새로운 예시를 추가하여 점진적으로 개선해야 합니다. 이 과정을 통해 모델의 출력을 지속적으로 개선할 수 있습니다.

    • 결과 분석: 클로드의 답변에서 원하는 것과 다른 패턴을 찾아보세요. 이렇게 하면 예시가 불분명하거나 오해의 소지가 있는 부분 또는 더 많은 예시가 도움이 될 수 있는 부분을 파악하는 데 도움이 될 수 있습니다.

    • 예시 추가: 클로드가 특정 유형의 입력에 어려움을 겪는다면 해당 시나리오를 구체적으로 다루는 추가 예제를 제공하세요.

    • 기존 예제 수정: 때로는 예제를 조금만 수정해도 큰 차이를 만들 수 있습니다. 다양한 표현, 형식 또는 구조로 실험하여 무엇이 가장 효과적인지 알아보세요.

    • Claude의 도움 받기: 좋은 예시를 작성하는 것은 어려운 일입니다! Claude에게 주어진 작업에 대한 예제의 다양성이나 관련성을 평가해 달라고 요청하거나 참고할 기존 예제 세트를 제공받아 새로운 예제를 만들 수 있습니다.

클로드에게 역할 부여하기(Give Claude a role)

각 사용 사례별 성능을 높이기 위해 Claude에게 전문가와 같은 특정한 역할을 부여합니다:

  1. 역할 프롬프팅이 작동하는 방식: 클로드에게 구체적인 역할을 부여함으로써, 그가 특정 상황이나 문제를 더 정확하게 이해하고 대응할 수 있도록 합니다. 예를 들어, 클로드에게 수학 문제를 해결하는 '수학 전문가' 역할을 부여하면 더 나은 성능을 발휘할 수 있습니다.

  2. 역할 프롬프팅을 사용할 때: 특히 기술적이거나 복잡한 작업을 수행할 때, 또는 특정 커뮤니케이션 스타일이 필요할 때 역할 프롬프팅을 사용하면 좋습니다. 이 방법은 클로드의 기본 성능을 향상시키는 데도 도움이 됩니다.

예를 들어, There are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there? 과 같은 문제를 풀어야 할 때는 다음과 같은 방식을 사용해볼 수 있습니다:

|Role|Content|
|---|---|
|User|You are a master logic bot designed to answer complex logic problems. Solve this logic puzzle. There are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there?|
|Assistant (Claude's response)|[Automatically outputting thinking step by step as part of its training...] Without additional clarification or assumptions, the logic puzzle does not provide enough information to determine the exact number of ducks. The answer could range from a minimum of 3 ducks to a maximum of 5 ducks, depending on the interpretation of the given information.|

  1. 역할 프롬프팅 예시: 다양한 청중에게 '왜 하늘이 파란색인지' 설명하도록 클로드에게 각기 다른 역할(유치원 선생님, 대학교수)을 부여하는 예시가 있습니다. 각 역할에 따라 클로드의 설명 스타일이 달라집니다.

|Role|Content|
|---|---|
|User|You are a kindergarten teacher. Succinctly explain why the sky is blue to your students.|
|Assistant (Claude's response)|Have you ever wondered why the sky looks so pretty and blue? The reason is because of the sunlight! When the sun's rays shine down through the Earth's atmosphere, they hit lots of tiny gas molecules in the air. The blue colors in the sunlight get scattered and bounced all around by these molecules. And that's what makes the sky look blue to our eyes! Isn't that neat? The bright blue sky is like nature's big colorful painting just for us.|

|Role|Content|
| --- | --- |
|User|You are a graduate physics professor. Succinctly explain why the sky is blue to your students.|
|Assistant (Claude's response)|The sky appears blue due to the phenomenon of Rayleigh scattering of sunlight by the molecules in the Earth's atmosphere. Sunlight, which is composed of a spectrum of wavelengths, interacts with the gaseous molecules in the atmosphere. The shorter wavelengths of visible light, corresponding to the blue and violet colors, are scattered more efficiently by these molecules than the longer wavelengths.<br /><br />This selective scattering of the shorter blue wavelengths in all directions by the atmospheric molecules is what causes the sky to appear blue when viewed from the Earth's surface. The longer wavelengths of red and orange, being less scattered, tend to pass through the atmosphere more directly, giving rise to the reddish hues we see during sunrise and sunset when the sunlight has to travel through a greater depth of the atmosphere.|

  1. 효과적인 역할 프롬프팅 팁: 클로드에게 역할을 부여할 때는 구체적인 맥락과 역할 정보를 제공하는 것이 중요합니다. 다양한 역할과 프롬프트를 실험하여 최적의 접근 방식을 찾아야 합니다.

XML 태그 사용(Use XML tags)

XML 태그를 함께 사용하여 프롬프트와 응답을 구조화하여 명확성을 높일 수 있습니다:

  1. XML 태그란 무엇인가?: XML 태그는 <tag>콘텐츠 내용</tag>와 같은 괄호 태그 내용을 감싸는데 사용합니다. 이 태그들은 명령, 예시 또는 입력 데이터를 구분하여 클로드가 맥락을 더 잘 이해하고 정확한 출력을 생성하도록 돕습니다.
    태그 이름에 있어, Claude가 특별히 더 잘 동작하는 표준적인 XML 태그는 없습니다. 예를 들어, <doc><document>와 마찬가지로 잘 동작합니다. 하지만 함수 호출 기능을 사용할 때에는 특정 태그 이름을 사용해야 합니다.

  2. XML 태그 사용 이유: XML 태그를 사용하면 프롬프트의 다양한 부분을 명확하게 구분하여 보다 정확한 반응을 유도할 수 있습니다. 특히 복잡한 프롬프트나 다양한 입력을 다룰 때 유용합니다.

  3. XML 태그 사용 방법: XML 태그를 사용하여 명령, 내용, 예시를 분리할 수 있으며, 변수 입력이 포함된 프롬프트 템플릿을 처리할 때도 XML 태그를 사용하여 콘텐츠 삽입 위치를 지정할 수 있습니다:

|Role|Content|
| --- | --- |
|User|Please analyze this document and write a detailed summmary memo according to the instructions below, following the format given in the example:<br /><document><br />{{DOCUMENT}}<br /></document><br /><br /><instructions><br />{{DETAILED_INSTRUCTIONS}}<br /></instructions><br /><br /><example><br />{{EXAMPLE}}<br /></example>|

다음은 특정한 변수 입력의 예시입니다:

|Role|Content|
| --- | --- |
|User|I will tell you the name of an animal. Please respond with the noise that animal makes.<br /><animal>{{ANIMAL}}</animal>|

구조화된 출력을 위한 요청 시에도 사용합니다:
|Role|Content|
| --- | --- |
|User|Please extract the key details from the following email and return them in XML tags:<br /><br />- Sender name in <sender></sender> tags<br />- Main topic in <topic></topic> tags<br />- Any deadlines or dates mentioned in <deadline></deadline> tags<br /><br /><email><br />From: John Smith<br />To: Jane Doe<br />Subject: Project X Update<br /><br />Hi Jane,<br /><br />I wanted to give you a quick update on Project X. We've made good progress this week and are on track to meet the initial milestones. However, we may need some additional resources to complete the final phase by the August 15th deadline.<br /><br />Can we schedule a meeting next week to discuss the budget and timeline in more detail?<br /><br />Thanks,<br />John<br /></email>|

다음과 같은 답변을 받으실 수 있습니다:
|Role|Content|
| --- | --- |
|Assistant (Claude's response)|<sender>John Smith</sender><br /><topic>Project X Update</topic><br /><deadline>August 15th<br /></deadline>`|

  1. XML 사용 모범 사례: XML 태그를 최대한 활용하려면 다음 팁을 염두에 두세요:
    • <instruction>이나 <example>, <input> 등과 같이, 태그에 포함된 콘텐츠를 반영하는 설명적인 태그 이름을 사용하세요.

    • 프롬프트 전체에서 태그 이름에 일관성을 유지해야 하며, 태그는 여는 태그<tag>와 닫는 태그</tag>의 쌍을 함께 사용해야 합니다.

    • 필요한 경우 태그를 중첩하여 사용할 수 있지만, 복잡성에 따라 5개 이상의 중첩 레이어가 있는 경우 성능 저하가 일어날 수 있습니다.

프롬프트 연결하기(Chain prompts)

복잡한 작업을 더 작고 관리하기 쉬운 단계로 나누어 더 나은 결과를 얻으세요:

  1. 체인 프롬프트란 무엇인가? (What is prompt chaining?): 체인 프롬프트는 복잡한 목표를 달성하기 위해 하나의 출력을 다음 입력으로 사용하여 작업을 순차적으로 처리하는 방법입니다. 이 방식은 정확도와 일관성을 향상시키는 데 도움이 됩니다.

  2. 체인 프롬프트 사용 시기 (When to use prompt chaining): 여러 단계를 요구하는 작업이나 복잡한 지시사항을 포함하는 경우, 체인 프롬프트를 사용하여 각 단계의 성능을 개선할 수 있습니다.

  3. 체인 프롬프트의 효과적인 사용 팁 (Tips for effective prompt chaining): 각 서브태스크를 단순하고 명확하게 유지하고, XML 태그를 사용하여 데이터를 구조화하는 것이 중요합니다.

  4. 예시 (Examples): 문서와 질문을 사용하여 답변을 생성하거나 문법 오류를 식별하고 이를 검증하는 등의 작업을 체인 프롬프트로 수행하는 방법을 제시합니다:

예제: 문서 및 인용문(quotes) 사용하여 질문에 답변하기

  • 질문가 함께 주어진 문서에로부터 Claude가 문서 내의 인용문들을 사용하여 답변을 생성하도록 합니다.

프롬프트 1. 인용문(quotes) 추출하기

|Role|Content|
| --- | --- |
|User|Here is a document, in <document></document> XML tags:<br /><br /><document><br />{{DOCUMENT}}<br /></document><br /><br />Please extract, word-for-word, any quotes relevant to the question {{QUESTION}}. Please enclose the full list of quotes in <quotes></quotes> XML tags. If there are no quotes in this document that seem relevant to this question, please say "I can't find any relevant quotes".|

프롬프트 2. (프롬프트 1의 {{QUOTES}} 출력을 사용하여) 답변하기

|Role|Content|
| --- | --- |
|User|I want you to use a document and relevant quotes from the document to answer a question.<br />Here is the document:<br /><document><br />{{DOCUMENT}}<br /></document><br /><br />Here are direct quotes from the document that are most relevant to the question:<br /><quotes><br />{{QUOTES}}<br /></quotes><br /><br />Please use these to construct an answer to the question "<br />{{QUESTION}}"<br /><br />Ensure that your answer is accurate and doesn't contain any information not directly supported by the quotes.|

클로드에게 생각하도록 하기(Let Claude think)

단계별 사고를 장려하여 Claude의 결과물 품질을 향상시킬 수 있습니다:

  1. 복잡한 질문에 대응: 클로드가 복잡한 문제에 직면했을 때, 단계별로 문제를 분해하여 접근하면 보다 세밀하고 정확한 대답을 할 수 있습니다. 이는 특히 논리적이거나 분석적인 사고가 필요한 문제에서 유용합니다.

|Role|Content|
| --- | --- |
|User|Use the following clues to answer the multiple-choice question below, using this procedure:<br />1. Go through the clues one by one and consider whether each is potentially relevant<br />2. Combine the relevant clues to reason out the answer to the question<br />3. Map the answer to one of the multiple choice options: (a), (b), or (c)<br /><br />Clues:<br />1. Miss Scarlett was the only person in the lounge.<br />2. The person with the pipe was in the kitchen.<br />3. Colonel Mustard was the only person in the observatory.<br />4. Professor Plum was not in the library nor the billiard room.<br />5. The person with the candlestick was in the observatory.<br /><br />Question: Was Colonel Mustard in the observatory with the candlestick?<br />(a) Yes; Colonel Mustard was in the observatory with the candlestick<br />(b) No; Colonel Mustard was not in the observatory with the candlestick<br />(c) Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick<br />|

  1. 단계별로 생각하게 하는 방법: 사용자는 프롬프트에 "단계별로 생각하라"는 지시를 포함시켜 클로드에게 문제를 분석적으로 접근하도록 할 수 있습니다. 이렇게 하면 클로드는 각 단계를 설명하면서 최종 결론에 도달합니다.

  2. 생각 과정 포착: 생각하는 과정을 시각화하기 위해 XML 태그를 사용하여 클로드의 생각과정과 최종 답변을 명확하게 구분할 수 있습니다. 이는 사용자가 클로드의 추론 과정을 보다 명확하게 이해하는 데 도움을 줍니다.

|Role|Content|
| --- | --- |
|User|[Rest of prompt] Before answering the question, please think about it step-by-step within <thinking></thinking> tags. Then, provide your final answer within <answer></answer> tags.|
|Assistant (prefill)|<thinking>|

(이는 아래에서 살펴볼 응답 미리 채워주기 기법을 사용한 것입니다.)

|Role|Content|
| --- | --- |
|Assistant (Claude's response)|[Reasoning through the problem step-by-step]<br /></thinking><br /><br /><answer><br />[Final answer]<br /></answer>|

  1. 고려 사항: 이 기법을 사용할 때는 클로드의 출력이 길어질 수 있으므로 응답 시간이 늘어날 수 있습니다. 따라서 사용 전에는 이러한 특성을 고려하여 적절한 상황에서 사용해야 합니다.

Claude의 응답 미리 채워주기(Prefill Claude's response)

원하는 방향으로 출력을 유도하기 위해 클로드의 응답의 시작부분을 미리 채우고 시작합니다:

  1. 클로드의 응답 미리 채우기 이유: 이 기법은 사용자가 특정 형식이나 내용으로 응답하기를 원할 때 유용합니다. 예를 들어, 미리 정해진 형식에 맞춰 정보를 정리하거나, 특정 단어나 문구로 응답을 시작하게 하여 응답의 일관성을 유지할 수 있습니다. 아래와 같은 경우, {로 시작하는 응답을 미리 채움으로써 Claude가 JSON 형식으로 답변을 하도록 유도할 수 있습니다.

|ole|Good Prompt|
| --- | --- |
|User|Please extract the name, size, price, and color from this product description and output it within a JSON object. <br/><br/> <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)|{|

Claude의 응답은 다음과 같습니다.

|Role|Response|
| --- | --- |
|Assistant (Claude's response)|"name": "SmartHome Mini", <br />"size": "5 inches wide",<br />"price": "$49.99",<br />"colors": [<br />"black",<br />"white"<br />]<br />}|

  1. 클로드의 응답을 어떻게 미리 채울까?: 사용자는 클로드에게 시작할 텍스트를 제공함으로써 응답의 방향을 설정할 수 있습니다. 이 방법은 특히 API를 통해 자동화된 시스템에서 유용하며, 구조화된 데이터 포맷에서 클로드가 필요한 정보를 정확하게 제공하도록 할 수 있습니다.

출력 형식 제어(Control output format)

일관성과 가독성을 보장하기 위해 원하는 출력 형식을 지정할 수 있습니다:

  1. 원하는 형식 지정하기: 사용자는 클로드에게 구체적인 출력 형식을 지정하면 결과물의 일관성과 정확성을 높일 수 있습니다. 이는 특히 데이터 처리나 보고서 작성 시 필수적인 요소로, 명확한 형식 지침이 중요합니다. 예를 들어, JSON, XML, HTML, Markdown 등 다양한 형식으로 응답하도록 설정할 수 있습니다. 이렇게 클로드에게 명확한 형식 지침을 제공함으로써 일관된 출력 형식을 보장합니다.

|Role|Content|
| --- | --- |
|User|Please write a haiku about a cat. Use JSON format with the keys "first_line", "second_line", and "third_line".|
|Assistant (Claude's response)|{<br />"first_line": "Soft furry feline",<br />"second_line": "Napping in the warm sunlight",<br />"third_line": "Purring contentedly"<br />}|

  1. 응답을 미리 채우기: 응답의 시작 부분을 미리 채워 넣음으로써 클로드가 지정된 형식에 맞춰 내용을 생성하도록 유도할 수 있습니다. 이 방법은 구조화된 데이터 포맷을 사용할 때 특히 유용합니다.

|Role|Content|
| --- | --- |
|User|Please generate a recipe for chocolate chip cookies in JSON format.|
|Assistant (prefill)|{|
|Assistant (Claude's response)|"title": "Chocolate Chip Cookies",<br />"ingredients": [<br />"2 1/4 cups all-purpose flour",<br />"1 tsp baking soda",<br />"1 tsp salt",<br />"1 cup unsalted butter, softened",<br />"3/4 cup granulated sugar",<br />"3/4 cup brown sugar",<br />"1 tsp vanilla extract",<br />"2 large eggs",<br />"2 cups semisweet chocolate chips"<br />],<br />"instructions": [<br />"Preheat the oven to 375°F (190°C) and line baking sheets with parchment paper.",<br />"In a medium bowl, whisk together the flour, baking soda, and salt. Set aside.",<br />"In a large bowl, beat the butter and sugars with an electric mixer until light and fluffy, about 2-3 minutes.",<br />"Beat in the vanilla and eggs one at a time until well combined.",<br />"Gradually stir the flour mixture into the butter mixture until just combined.",<br />"Fold in the chocolate chips.",<br />"Drop rounded tablespoons of the dough onto the prepared baking sheets, about 2 inches apart.",<br />"Bake for 9-11 minutes, until the edges are golden brown.",<br />"Allow the cookies to cool on the baking sheets for 5 minutes before transferring to a wire rack to cool completely."<br />],<br />"yield": "About 3 dozen cookies"<br />}|

  1. 예시 제공: 적절한 출력 형식을 더 명확히 전달하기 위해 예시를 제공할 수 있습니다. 이는 클로드가 요구 사항을 더 잘 이해하고 적절한 형식의 응답을 생성하도록 도와, 특히 복잡한 형식을 요구하는 작업에 유용합니다.

|Role|Content|
| --- | --- |
|User|Your task is to write a poem. Here are some examples of ideal formatting for the poem:<br /><br /><poem><br />Title: "Autumn Leaves"<br />Verse 1:<br />Crisp autumn leaves dance<br />In the gentle, chilly breeze<br />A colorful sight<br /><br />Verse 2:<br />Red, orange, and gold<br />Painting the world with beauty<br />Before winter comes<br /></poem><br /><br /><poem><br />Title: "Moonlit Night"<br />Verse 1:<br />Moonlight casts shadows<br />Across the tranquil garden<br />A peaceful retreat<br /><br />Verse 2:<br />Stars twinkle above<br />As crickets sing their nightsong<br />Nature's lullaby<br /></poem><br /><br />Now, please write a poem about a sunset, following the formatting of the examples above.|
|Assistant (prefill)|<poem>|
|Assistant (Claude's response)|Title: "Sunset Symphony"<br />Verse 1:<br />Fiery sun descends<br />Painting the sky with wonder<br />A masterpiece forms<br /><br />Verse 2:<br />Pinks, purples, and reds
Blending in pure harmony<br />Day bids night hello<br /></poem>|

  1. 출력 제어를 위한 팁: 효과적인 출력 제어를 위해 다양한 예시와 명확한 지침을 제공해야 합니다. 가능한 여러 종류의 예시를 제공하며 원하는 형식을 강조하고, 실험을 통해 최적의 방법을 찾아내는 것이 중요합니다. 이러한 과정을 통해 다양한 기법을 조합해 보며 최적의 결과를 도출해나가며 클로드의 성능을 지속적으로 개선할 수 있습니다.

Claude에게 다시 작성할 것을 요청하기 (Ask Claude for rewrites)

빨간펜(rubric)으로 수정을 요청하는 부분을 알려줘서 Claude가 출력을 반복하고 개선하도록 합니다:

  1. 재작성 요청의 이유: 클로드의 초기 응답이 정확하지 않거나 기대에 미치지 못할 때, 재작성을 요청하여 출력을 개선할 수 있습니다. 사용자는 특정 형식, 스타일 또는 내용상의 세부 사항을 명확히 하여 클로드가 더 정확하게 반응하도록 유도할 수 있습니다.

  2. 재작성 요청 방법: API를 통해 이전에 생성된 텍스트를 포함시키고, 재작성을 위한 구체적인 지시사항을 추가합니다. 예를 들어, 문단을 다시 작성하되 특정 주제에 집중하도록 요청할 수 있습니다.

|Role|Prompt|
| --- | --- |
|User|Here's a paragraph:<br /><paragraph><br />{{PARAGRAPH}}<br /></paragraph><br /><br />I'd like you to rewrite it using the following instructions:<br /><instructions><br />{{INSTRUCTIONS}}<br /></instructions><br /><br />Please put your rewrite in <rewrite></rewrite> tags.|
|Assistant (prefill)|<rewrite>|

  1. 효과적인 재작성 지시 작성: 재작성을 위한 지시는 명확하고 구체적이어야 합니다. 원하는 형식, 톤, 스타일, 추가 정보 등을 포함시켜 클로드가 기대하는 바를 정확히 이해할 수 있도록 해야 합니다.

|Role|Prompt|
|---|---|
|User|Tell me about all the ways I can get fitter.|
|Assistant (Claude's response)|Here are some ways you can get fitter: [list-style response]|
|User|Rewrite this as a single paragraph of text, focusing on the most effective strategies.|
|Assistant (Claude's response)|If you're looking to get fitter, some of the most effective strategies include: [brief paragraph-style response]|

  1. 반복적인 재작성 과정: 때로는 하나의 재작성만으로는 완벽한 결과를 얻기 어렵습니다. 이럴 때는 여러 번의 재작성을 통해 점차적으로 결과를 개선하고, 각 단계마다 피드백을 제공하여 클로드가 사용자의 선호도를 학습하도록 할 수 있습니다.

긴 컨텍스트 창 팁(Long context window tips)

Claude의 긴 컨텍스트 창을 활용하도록 프롬프트를 최적화 할 수 있습니다:

다음은 "긴 컨텍스트 창 팁 (Long Context Window Tips)" 문서의 각 섹션에 대한 자세한 설명입니다:

  1. 긴 문서 다루기 (Handling Long Documents): 긴 문서를 다룰 때는 중요한 정보를 문서의 앞부분에 배치하고, 질문을 문서의 끝에 두어야 합니다. 이렇게 하면 클로드가 전체 문서를 통틀어 필요한 정보를 효과적으로 처리하고 적절한 답변을 제공할 수 있습니다.
Here are some documents for you to reference for your task:  
  
<documents>  
<document index="1">  
<source>  
(a unique identifying source for this item - could be a URL, file name, hash, etc)  
</source>  
<document_content>  
(the text content of the document - could be a passage, web page, article, etc)  
</document_content>  
</document>  
<document index="2">  
<source>  
(a unique identifying source for this item - could be a URL, file name, hash, etc)  
</source>  
<document_content>  
(the text  content of the document - could be a passage, web page, article, etc)  
</document_content>  
</document>  
...  
</documents>  
  
[Rest of prompt]  
  1. 문서-질문 배치 (Document-query Placement): 문서와 관련된 질문은 문서 데이터가 제공된 후에 위치시켜야 합니다. 이 구조는 클로드가 문서 전체를 참고하여 더 정확한 답변을 할 수 있게 만듭니다.

  2. 문서 Q&A 작성 팁 (Tips for Document Q&A): 문서 기반 질의응답 작업을 할 때는 질문을 문서 끝에 배치하고, 관련 인용문을 찾아 응답에 반영하도록 합니다. 이는 결과의 정확성을 높이는 데 기여합니다.

|Role|Content|
| --- | --- |
|User|I'm going to give you a document. Read the document carefully, because I'm going to ask you a question about it. Here is the document: <document>{{TEXT}}</document><br /><br />First, find the quotes from the document that are most relevant to answering the question, and then print them in numbered order in <quotes></quotes> tags. Quotes should be relatively short. If there are no relevant quotes, write "No relevant quotes" instead.<br /><br />Then, answer the question in <answer></answer> tags. Do not include or reference quoted content verbatim in the answer. Don't say "According to Quote [1]" when answering. Instead make references to quotes relevant to each section of the answer solely by adding their bracketed numbers at the end of relevant sentences.<br /><br />Thus, the format of your overall response should look like what's shown between the <examples></examples> tags. Make sure to follow the formatting and spacing exactly.<br /><br /><examples><br />[Examples of question + answer pairs, with answers written exactly like how Claude's output should be structured]<br /></examples><br /><br />If the question cannot be answered by the document, say so.<br /><br />Here is the first question: {{QUESTION}}|

  1. 다지선다 문제 생성 (Multiple Choice Question Generation): 문서를 기반으로 다지선다 문제를 만들 때는 문서 내용에 기반한 예시 문제와 답을 제공합니다. 이는 클로드가 문제를 생성할 때 일관된 형식과 내용을 유지하도록 돕습니다.

|Role|Content|
| --- | --- |
|User|Your task is to generate multiple choice questions based on content from the following document:<br /><document><br />{{DOCUMENT}}<br /></document><br /><br />Here are some example multiple choice questions and answers based on other parts of the text:<br /><examples><br />Q1: [Example question 1, created from information within the document]<br />A. [Answer option A]<br />B. [Answer option B]<br />C. [Answer option C]<br />D. [Answer option D]<br />Answer: [Correct answer letter]<br /><br />Q2: [Example question 2, created from information within the document]<br />A. [Answer option A]<br />B. [Answer option B]<br />C. [Answer option C]<br />D. [Answer option D]<br />Answer: [Correct answer letter]<br /></examples><br /><br />Instructions:<br />1. Generate 5 multiple choice questions based on the provided text.<br />2. Each question should have 4 answer options (A, B, C, D).<br />3. Indicate the correct answer for each question.<br />4. Make sure the questions are relevant to the text and the answer options are all plausible.|

더 읽어보기

https://docs.anthropic.com/claude/docs/prompt-engineering

<br /><br />


이 글은 GPT 모델로 정리한 글을 바탕으로 한 것으로, 원문의 내용 또는 의도와 다르게 정리된 내용이 있을 수 있습니다. 관심있는 내용이시라면 원문도 함께 참고해주세요! 읽으시면서 어색하거나 잘못된 내용을 발견하시면 덧글로 알려주시기를 부탁드립니다. 🤗

⚠️광고⚠️: 🔥파이토치 한국 사용자 모임🇰🇷이 정리한 이 글이 유용하셨나요? 회원으로 가입하시면 주요 글들을 이메일💌로 보내드립니다! (기본은 Weekly지만 Daily로 변경도 가능합니다.)