Prerequisites
Managing evaluators through the SDK requires:- Python:
langsmith>=0.8.17(PyPI) - TypeScript:
langsmith>=0.7.10(npm)
For installation and setup, refer to the Python SDK documentation and TypeScript SDK documentation.
LANGSMITH_API_KEY and LANGSMITH_ENDPOINT environment variables. Configure your API key through environment variables rather than hardcoding it.
In the following examples, replace placeholders such as <evaluator-uuid> with the corresponding information from LangSmith.
Create an evaluator
Code evaluator
A code evaluator scores each run or example with a function that you define.LLM-as-a-judge evaluator
An LLM-as-a-judge evaluator references a prompt from the prompt hub and maps your run or example fields to the prompt variables.The prompt must be a structured prompt (type
StructuredPrompt). A StructuredPrompt combines a prompt template with an output schema, ensuring the model returns data in a defined structure.prompt_repo_handle is the prompt’s internal repository name, not its display title or URL. To find it, list your workspace prompts and read the repo_handle field, or retrieve a specific prompt by its identifier in LangSmith. The identifier of a prompt can be in the format:
promptName(for private prompts), for examplemy-prompt.owner/promptName(for public prompts), for examplelangchain-ai/correctness.
Retrieve an evaluator
Fetch a single evaluator by its ID to read its configuration, including its name, type, feedback keys, and run rules.Update an evaluator
Pass the field that matches the evaluator type:code_evaluator for a code evaluator or llm_evaluator for an LLM-as-a-judge evaluator. update changes only the fields you pass.
Configure runtime settings
An LLM-as-a-judge evaluator accepts additional settings that control how it scores traces:variable_mapping: Maps run or example fields to the judge prompt variables. It applies when the evaluator runs.use_corrections_datasetandnum_few_shot_examples: Enable few-shot learning from human score corrections. They apply only when the evaluator is attached to a project or dataset and corrections have been submitted.
These settings take effect on the next evaluation run, not when you call
update.List evaluators
Filter by name, type, feedback key, attached resource, or tag value, and sort or paginate the results.list() auto-paginates through every match when you iterate the returned object directly. limit sets the per-request page size (1 to 100), not the total number of results. sort_by is optional, accepts created_at or updated_at, and defaults to created_at.
Track evaluator spend
Retrieve estimated USD spend and trace counts for your evaluators:period_start: A date-only ISO string, such as2026-06-29. Passing a datetime returns a 400 error.- Window:
period_startstarts a fixed 7-day window that includesperiod_startand the six days after it. The window is half-open,[period_start, period_start + 7 days), soperiod_end(period_startplus 7 days) is excluded. For example, aperiod_startof2026-06-29covers2026-06-29through2026-07-05, and2026-07-06is excluded.
- Window:
type: Scopes results to a single evaluator type,llmorcode. Omit it to include all types.- Empty result: If no spend is recorded for the window, the returned
groupslist is empty.
Pass exactly one of
group_by, evaluator_id, session_id (the LangSmith tracing project UUID), or dataset_id.Delete an evaluator
You cannot delete an evaluator while it is attached to a tracing project or dataset. Setdelete_run_rules to true to delete the run rules that reference the evaluator before deleting the evaluator.
Related
- Manage evaluators: View and manage evaluators in the LangSmith UI.
- Set up LLM-as-a-judge online evaluators: Configure LLM-as-a-judge online evaluators in the LangSmith UI.
- Set up online code evaluators: Configure online code evaluators in the LangSmith UI.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

