평가를 실행하기 위해 필요한 세 가지 주요 요소가 있습니다:
  1. 테스트 입력과 예상 출력의 dataset.
  2. 평가 대상인 target function.
  3. target function의 출력을 점수화하는 Evaluators.
이 가이드는 애플리케이션의 어느 부분을 평가하는지에 따라 target function을 정의하는 방법을 보여줍니다. dataset 생성 방법evaluator 정의 방법, 그리고 평가 실행의 전체 예제는 여기를 참조하세요.

Target function signature

코드에서 애플리케이션을 평가하려면 애플리케이션을 실행할 방법이 필요합니다. evaluate() (Python/TypeScript)를 사용할 때 target function 인자를 전달하여 이를 수행합니다. 이는 dataset Example의 입력을 받아 애플리케이션 출력을 dict로 반환하는 함수입니다. 이 함수 내에서 원하는 방식으로 애플리케이션을 호출할 수 있습니다. 또한 원하는 방식으로 출력을 포맷할 수 있습니다. 핵심은 정의하는 모든 evaluator 함수가 target function에서 반환하는 출력 형식과 호환되어야 한다는 것입니다.
from langsmith import Client

# 'inputs' will come from your dataset.
def dummy_target(inputs: dict) -> dict:
    return {"foo": 1, "bar": "two"}

# 'inputs' will come from your dataset.
# 'outputs' will come from your target function.
def evaluator_one(inputs: dict, outputs: dict) -> bool:
    return outputs["foo"] == 2

def evaluator_two(inputs: dict, outputs: dict) -> bool:
    return len(outputs["bar"]) < 3

client = Client()
results = client.evaluate(
    dummy_target,  # <-- target function
    data="your-dataset-name",
    evaluators=[evaluator_one, evaluator_two],
    ...
)
evaluate()는 자동으로 target function을 추적합니다. 즉, target function 내에서 추적 가능한 코드를 실행하면 이것도 target trace의 하위 run으로 추적됩니다.

예제: 단일 LLM 호출

from langsmith import wrappers
from openai import OpenAI

# Optionally wrap the OpenAI client to automatically
# trace all model calls.
oai_client = wrappers.wrap_openai(OpenAI())

def target(inputs: dict) -> dict:
  # This assumes your dataset has inputs with a 'messages' key.
  # You can update to match your dataset schema.
  messages = inputs["messages"]
  response = oai_client.chat.completions.create(
      messages=messages,
      model="gpt-4o-mini",
  )
  return {"answer": response.choices[0].message.content}

예제: Non-LLM 컴포넌트

from langsmith import traceable

# Optionally decorate with '@traceable' to trace all invocations of this function.
@traceable
def calculator_tool(operation: str, number1: float, number2: float) -> str:
  if operation == "add":
      return str(number1 + number2)
  elif operation == "subtract":
      return str(number1 - number2)
  elif operation == "multiply":
      return str(number1 * number2)
  elif operation == "divide":
      return str(number1 / number2)
  else:
      raise ValueError(f"Unrecognized operation: {operation}.")

# This is the function you will evaluate.
def target(inputs: dict) -> dict:
  # This assumes your dataset has inputs with `operation`, `num1`, and `num2` keys.
  operation = inputs["operation"]
  number1 = inputs["num1"]
  number2 = inputs["num2"]
  result = calculator_tool(operation, number1, number2)
  return {"result": result}

예제: Application 또는 agent

from my_agent import agent

      # This is the function you will evaluate.
def target(inputs: dict) -> dict:
  # This assumes your dataset has inputs with a `messages` key
  messages = inputs["messages"]
  # Replace `invoke` with whatever you use to call your agent
  response = agent.invoke({"messages": messages})
  # This assumes your agent output is in the right format
  return response
dataset에 정의된 입력을 받아들이고 evaluator에서 사용하려는 출력 형식을 반환하는 LangGraph/LangChain agent가 있다면, 해당 객체를 target으로 직접 전달할 수 있습니다:
from my_agent import agent
from langsmith import Client
client = Client()
client.evaluate(agent, ...)

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I