모델이 똑똑하게 말하게 만드는 프롬프트 작성법

Published at 2025-08-06

최근에 Google Study Jam x Women IT's 스터디를 진행하게 되었다.

[AI] Gemini 기초 및 애플리케이션 개발 적용 스터디

나는 이 스터디에 신청했고, 운 좋게 선발되어서 스터디에 참여할 수 있었다.

앞으로 스터디를 진행하면서 배운 내용을 정리할 예정.


프롬프트 엔지니어링 권장사항(Prompt engineering best practices)

“unfancy”한 프롬프트 엔지니어링 하는 방법

  • Be concise: 간결하게 작성하기
  • Be specific, and well-defined: 구체적이고 명확하게 정의하기
  • Ask one task at a time: 한 번에 하나의 작업만 요청하기
  • Improve response quality by including examples: 예시를 들어 대답 품질 개선하기
  • Turn generative tasks to classification tasks to improve safety: 생성 작업 대신 분류 작업을 요청하여 안정성 개선하기

1. 간결하게 작성하기

🛑 prompt = "What do you think could be a good name for a flower shop that specializes in selling bouquets of dried flowers more than fresh flowers?”

✅ prompt = "Suggest a name for a flower shop that sells bouquets of dried flowers”

2. 구체적이고 명확하게 정의하기

🛑 prompt = "Tell me about Earth”

✅ prompt = "Generate a list of ways that makes Earth unique compared to other planets”

3. 한 번에 하나의 작업만 요청하기

🛑 prompt = "What's the best method of boiling water and why is the sky blue?”

✅ prompt = "What's the best method of boiling water?”

✅ prompt = "Why is the sky blue?”


출력 변동성 줄이기

할루시네이션 주의하기

LLM은 그럴듯하게 말하지만 가짜 정보도 생성한다. 이런 헛소리 같은 출력을 흔히 “hallucination“이라고 부른다.

그렇다고 “출처 알려줘!” 라고 모델에 시킨다고 해서 이 문제가 해결되지는 않는다.

왜냐하면, 거짓된 출처나 엉터리 인용을 만들어내는 경우도 있기 때문이다.

환각 문제는 LLM의 근본적인 한계이자, 아직 진행 중인 연구 주제다.

그래서 모델이 그럴듯하게 말한다고 해서 모두 맞는 말은 아니라는 걸 인지해야 한다.

하지만 만약 LLM을 창작 목적으로 쓴다면 이 환각 기능이 오히려 도움이 될 수 있다. (예: 시, 소설, 스토리텔링, 상상 대화 등)

temperature 값을 1.0로 설정하면 모델이 좀 더 모험적인 선택을 하는데 그 결과, 정확하지 않은데도 매우 자신 있는 답변을 하게 된다.

generation_config = GenerateContentConfig(temperature=1.0)

prompt = "What day is it today?"

response = client.models.generate_content(model=MODEL_ID, contents=prompt)
display(Markdown(response.text))

<table style="border-collapse: collapse; width: 42.0931%; height: 147px;" border="1" data-ke-align="alignLeft" data-ke-style="style14"><tbody><tr><td style="width: 34.8327%;"><span style="font-family: 'Nanum Gothic';" data-token-index="0">Temperature</span></td><td style="width: 65.1673%;"><span style="font-family: 'Nanum Gothic';" data-token-index="0">의미</span></td></tr><tr><td style="width: 34.8327%;"><span style="font-family: 'Nanum Gothic';">0.0</span></td><td style="width: 65.1673%;"><span style="font-family: 'Nanum Gothic';">가장 확률 높은 단어만 고름</span></td></tr><tr><td style="width: 34.8327%;"><span style="font-family: 'Nanum Gothic';">1.0</span></td><td style="width: 65.1673%;"><span style="font-family: 'Nanum Gothic';">확률 분포 그대로 따름</span></td></tr><tr><td style="width: 34.8327%;"><span style="font-family: 'Nanum Gothic';">>1.0</span></td><td style="width: 65.1673%;"><span style="font-family: 'Nanum Gothic';" data-token-index="0">더 무작위하게</span></td></tr></tbody></table>


시스템 지시문을 사용해서 모델의 정확성을 높이기

할루시네이션이나 질문과 맞지 않는 답변을 할 가능성을 줄이는 방법 중 하나는 ‘시스템 지시문’을 주는 것이다.

예를 들어, 이탈리아에서 유명한 관광지 중 하나에 대해 질문을 한다고 해보자.

generation_config = GenerateContentConfig(temperature=1.0)

chat = client.chats.create(
    model=MODEL_ID,
    config=GenerateContentConfig(
        system_instruction=[
            "Hello! You are an AI chatbot for a travel web site.",
            "Your mission is to provide helpful queries for travelers.",
            "Remember that before you answer a question, you must check to see if it complies with your mission.",
            "If not, you can say, Sorry I can't answer that question.",
        ]
    ),
)

prompt = "What is the best place for sightseeing in Milan, Italy?"

response = chat.send_message(prompt)
display(Markdown(response.text))
prompt = "How do I make pizza dough at home?"

response = chat.send_message(prompt)
display(Markdown(response.text))

-> Sorry, I can't answer that question.


생성 작업 대신 분류 작업을 요청하여 안정성 개선하기

출력 변동성을 줄이기 위해 생성형 작업을 분류형 작업으로 바꾸는 것이다. (쉽게 말하면 분류 작업이란건 모델이 Yes/No로 대답하기 쉬운 질문을 말한다.)

생성형 작업은 출력 결과가 들쭉날쭉해지기 쉽기 때문이다.

아래 프롬프트는 아이디어를 뽑아내는 데엔 유용하지만, 답변이 매우 다양하고 예측 불가능하다.

prompt = "I'm a high school student. Recommend me a programming activity to improve my skills."

response = client.models.generate_content(model=MODEL_ID, contents=prompt)
display(Markdown(response.text))

아래 프롬프트는 선택지를 주어, 출력 결과를 통제하는데 유용하다.

prompt = """I'm a high school student. Which of these activities do you suggest and why:
a) learn Python
b) learn JavaScript
c) learn Fortran
"""

response = client.models.generate_content(model=MODEL_ID, contents=prompt)
display(Markdown(response.text))

예시를 들어 대답 품질 개선하기

응답 품질을 높이는 또 다른 방법은 프롬프트에 예시를 추가하는 것이다.

LLM은 프롬프트 내의 예시를 통해 맥락 내 학습을 한다.

보통 예시 1~5개면 충분하며, 너무 많은 예시를 추가하면 모델이 그 예시들에 과적합(overfit)되어 오히려 응답 품질이 떨어질 수 있다.

prompt = """Decide whether a Tweet's sentiment is positive, neutral, or negative.

Tweet: I loved the new YouTube video you made!
Sentiment: positive

Tweet: That was awful. Super boring 😠
Sentiment: negative

Tweet: Something surprised me about this video - it was actually original. It was not the same old recycled stuff that I always see. Watch it - you will not regret it.
Sentiment:
"""