쿼리별 Prompt Routing: LLM을 위한 쿼리 단위 프롬프트 선택
Querywise Prompt Routing for Large Language Models
TL;DR Highlight
프롬프트 라우팅 기법이 각 쿼리에 최적으로 매칭되는 프롬프트를 자동으로 선택하여 LLM 응답 정확도를 향상시킨다.
Who Should Read
LLM 기반 서비스에서 프롬프트를 여러 버전 관리하거나 A/B 테스트를 운영 중인 백엔드/AI 개발자. 특히 추론(reasoning) 태스크에서 zero-shot 프롬프트 성능을 올리고 싶은 개발자.
Core Mechanics
- 프롬프트를 전체 트래픽에 동일하게 쓰는 대신, 쿼리 하나하나에 맞는 프롬프트를 골라주는 라우터를 학습
- 과거 프롬프트-응답 로그만 있으면 학습 가능 — 정답 레이블(gold answer)이나 추가 LLM 호출 불필요
- 선호도 모델(preference model)을 오프라인으로 학습해 inference 시 LLM 호출 없이 즉시 프롬프트 점수 산출
- N개 후보 프롬프트 중 최고 점수(best-of-N)를 선택하는 구조라 후보를 늘릴수록 성능 향상 가능
- 특정 LLM 아키텍처에 종속되지 않아 ChatGPT, Llama 등 대화형 LLM이면 그대로 적용 가능
- 학습 때 못 본 새 프롬프트와 새 쿼리에도 일반화되어 프롬프트 풀을 지속 확장 가능
Evidence
- 표준 산술 추론 벤치마크에서 쿼리 무관(distribution-level) 프롬프팅 대비 일관된 정확도 향상
- confidence 기반 선택기(confidence-based selector)보다 우수한 성능을 여러 LLM 규모에서 확인
- ablation 실험에서 학습된 리워드가 미학습 프롬프트·쿼리 모두에 일반화됨을 확인
How to Apply
- 기존 프롬프트 로그(쿼리 + 프롬프트 + 응답)가 있다면 preference 모델을 오프라인으로 학습해 새 쿼리 유입 시 best-of-N 프롬프트를 자동 선택하도록 라우터 레이어를 추가
- 프롬프트 A/B 테스트를 운영 중이라면 각 프롬프트의 히스토리 로그를 학습 데이터로 써서 라우터를 초기화하고, 이후 신규 프롬프트 버전을 후보 풀에 추가하기만 하면 됨
- 추론(reasoning) 외 태스크에서도 프롬프트-응답 로그만 확보되면 동일 파이프라인 적용 가능 — 모델 fine-tuning 없이 프롬프트 레벨에서 성능 개선이 필요한 상황에 유용
Code Example
# 쿼리별 프롬프트 라우팅 개념 구현 예시 (pseudo-code)
from sentence_transformers import SentenceTransformer
from sklearn.linear_model import LogisticRegression
import numpy as np
# 1. 과거 로그에서 (query, prompt, score) 쌍 준비
# score: 응답 품질 기반 preference label (예: 0 or 1)
logs = [
{"query": "3 + 5 * 2는?", "prompt": "단계별로 계산하세요.", "score": 1},
{"query": "3 + 5 * 2는?", "prompt": "바로 답하세요.", "score": 0},
# ... 더 많은 로그
]
encoder = SentenceTransformer("all-MiniLM-L6-v2")
# 2. (query + prompt) 쌍을 임베딩해 preference 모델 학습
X = []
y = []
for log in logs:
pair_text = log["query"] + " [SEP] " + log["prompt"]
X.append(encoder.encode(pair_text))
y.append(log["score"])
reward_model = LogisticRegression()
reward_model.fit(np.array(X), y)
# 3. 새 쿼리에 대해 best-of-N 프롬프트 선택
def route_prompt(query: str, candidate_prompts: list[str]) -> str:
scores = []
for prompt in candidate_prompts:
pair_text = query + " [SEP] " + prompt
emb = encoder.encode(pair_text).reshape(1, -1)
score = reward_model.predict_proba(emb)[0][1] # positive class prob
scores.append(score)
best_idx = int(np.argmax(scores))
return candidate_prompts[best_idx]
# 사용 예
candidates = [
"단계별로 풀어서 최종 답을 알려주세요.",
"수식을 그대로 계산해 숫자만 답하세요.",
"먼저 연산 순서를 확인한 뒤 계산하세요.",
]
query = "(12 / 4) + 3 * 7의 결과는?"
best_prompt = route_prompt(query, candidates)
print(f"선택된 프롬프트: {best_prompt}")Terminology
관련 논문
다국어 Reasoning Cascade는 더 많은 Context가 필요하다
번역 cascade 파이프라인에서 원본 질문을 마지막까지 유지하면 추가 학습 없이 다국어 성능이 크게 오른다.
Back-and-Forth를 줄여라: Structured Prompting 비교 연구
체크리스트 형식으로 프롬프트를 구조화하면 LLM 답변 품질도 높아지고 토큰도 적게 쓴다.
Training-Free Cultural Alignment: Persona 불일치를 활용한 LLM 문화적 정렬
재학습 없이 각 나라의 도덕적 가치관에 맞게 LLM 출력을 조정하는 추론 시점 기법 DISCA 제안
Claude Code에서 HTML을 출력 포맷으로 쓰는 이유: Markdown보다 나은 점들
Claude Code 팀이 Markdown 대신 HTML을 LLM 출력 포맷으로 선호하기 시작한 이유와 그 실용적 장점을 정리한 글로, AI와 함께 문서/스펙/대시보드를 만드는 워크플로우에 직접적인 영향을 준다.
언제 투표하고 언제 다시 쓸까: Disagreement 기반 Test-Time Scaling 전략 라우팅
모델 출력이 얼마나 일치하는지 보고 쉬운 문제엔 majority voting, 어려운 문제엔 문제 rewriting을 자동으로 선택해 정확도 3~7% 올리고 샘플링 비용도 줄이는 학습 불필요 프레임워크.
Less Is More: Android 앱에 On-Device Small Language Model 통합할 때 실제로 겪는 엔지니어링 문제들
Wordle 게임에 온디바이스 SLM(Gemma 4 E2B, Qwen3 0.6B)을 5일간 붙여보면서 발견한 5가지 실패 유형과 8가지 실용 해결책 정리
확장 가능한 Synthetic Data 생성을 위한 Dynamic Context Evolution
Original Abstract (Expand)
This paper treats prompt choice as a per-query decision problem for large language models, learning an of-fline proxy reward that can score query-prompt pairs without additional model calls or access to gold answers at inference time. Using prior prompt-response logs as demonstrations, the method trains a preference model over prompts and then selects a best-of-N instruction per query to boost arithmetic reasoning accuracy under strict zero-shot conditions. The pipeline reduces interaction cost by shifting evaluation and optimization offline, while preserving the natural-language prompt space so the approach remains model-agnostic and immediately deployable across chat-oriented LLMs. Experiments on standard reasoning benchmarks show consistent gains over distribution-level, query-agnostic prompting and over confidence-based selectors, with improvements holding across multiple LLM scales. Ablations confirm that the learned reward generalizes to unseen prompts and queries, enabling robust prompt routing at inference without additional gradient updates or tool-specific supervision.