LLM-as-Judge Framework for Production LLM Evaluation and Improvement

segment · Tech · 2024 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Customer data platform audience generation

Twilio Segment needed a way to evaluate natural-language audience generation where outputs are ASTs with many semantically valid forms, making exact-match evaluation unusable for production iteration.

Constraints:

Architecture

Segment built an LLM-as-judge evaluation pipeline around real customer ASTs. A question-generator agent reverse-generates synthetic prompts from ground-truth ASTs, an AST-generator agent produces candidate ASTs from those prompts, and a judge agent scores the generated AST against the original AST. The resulting scores become the evaluation scoreboard for model, prompt, memory, and architecture changes in CustomerAI audiences.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  Audience_Builder_UI["Audience Builder UI"] --> Real_World_AST_Input["Real World AST Input"]
  Real_World_AST_Input --> LLM_Question_Generator_Agent["LLM Question Generator Agent"]
  LLM_Question_Generator_Agent --> User_Prompt["User Prompt"]
  User_Prompt --> LLM_AST_Generator_Agent["LLM AST Generator Agent"]
  LLM_AST_Generator_Agent --> Generated_AST["Generated AST"]
  Generated_AST --> LLM_Judge_Agent["LLM Judge Agent"]
  Real_World_AST_Input --> LLM_Judge_Agent
  LLM_Judge_Agent --> Evaluation_scoreboard["Evaluation scoreboard"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Audience Builder UI Marketer-facing interface that captures complex segment logic and produces real-world ASTs. Real World AST Input
Real World AST Input Ground-truth ASTs created by customers or labellers and used as evaluation references. Audience Builder UI, LLM Question Generator Agent, LLM Judge Agent
LLM Question Generator Agent Reverse-generates plausible user prompts from ground-truth ASTs so prompt-output eval pairs can be constructed. Real World AST Input, User Prompt
User Prompt Synthetic natural-language input produced from an AST and then fed to the AST generator. LLM Question Generator Agent, LLM AST Generator Agent
LLM AST Generator Agent Production-style generation agent that converts prompts into candidate ASTs. User Prompt, Generated AST, LLM Agent
Generated AST Candidate AST output evaluated for semantic equivalence with ground truth. LLM AST Generator Agent, LLM Judge Agent
LLM Judge Agent Scores generated ASTs against real-world ASTs and provides reasoning for human and engineering interpretation. Generated AST, Real World AST Input, Evaluation scoreboard
Evaluation scoreboard Score layer used to compare models, prompts, RAG or memory additions, and pipeline architecture choices. LLM Judge Agent

Data flow

Customer-created ASTs from the Audience Builder become ground truth. The LLM question generator derives likely natural-language prompts from those ASTs, the AST generator produces new ASTs from the synthetic prompts, and the judge compares generated ASTs with real-world ASTs. Engineers use the judge score and chain-of-thought reasoning to compare model families, prompt variants, context-window sizes, and future RAG or memory additions.

3 supporting quotes
“we have a large dataset of ASTs, those ASTs were generated by our UI, not via a prompt.”article, stated
“we built an LLM Question Generator Agent that takes a “ground truth” AST and generates a prompt.”article, stated
“The LLM Judge Agent evaluates the Generated AST and provides a score based on its alignment with the Real World AST Input.”article, stated

Why this architecture

The architecture turns ambiguous semantic-equivalence evaluation into a repeatable scoreboard. Synthetic prompt generation solves the missing-input problem, and a judge model handles cases where strict heuristics would reject valid AST variants.

3 supporting quotes
“Traditional evaluation approaches using exact matching or rule-based systems would fail in this context because they cannot account for semantic equivalence.”summary, stated
“This may seem counterintuitive, as we normally think of prompts as the input into models. But to construct the necessary eval set, we needed to extract prompts from the AST.”article, stated
“Further, these baseline scores enable us to compare future iterations & optimizations.”article, stated

Models used: LLM question generator · LLM AST generator · LLM judge · GPT-4 · gpt-4-32k-0613 · Claude 3 Opus

Scale

Alternatives considered (roads not taken)

Exact-match or rule-based AST evaluation

Rejected because: Multiple ASTs can represent the same audience meaning, so strict matching would penalize valid generations.

“For complex audiences, AST syntax can get complex, and there are many ways to express an audience that have the same meaning and an identical result.”article, stated

Continuous 0-100 judge scores

Rejected because: The team observed that LLMs tended to collapse continuous scores into extremes, so they used a discrete 1-5 scale.

“LLMs struggle with continuous scores. For example, if asking LLM to give a score from 0 to 100, LLM tends to only output discrete values such as 0 and 100.”article, stated

Evaluate only a single model or context-window setup

Rejected because: The scoreboard was used to compare Claude, GPT-4 variants, and context-window sizes.

“There is a remarkable similarity in the final scores between the 8K context length version and the 32k context window version which proves the stability of this method.”article, stated

Patterns

llm-as-judge (evaluation)

A separate judge model scored generated ASTs against ground-truth ASTs and produced reasoning used by engineers to compare models and architectures.

“LLM-as-Judge asks a model (the “judge”) to evaluate, compare, and score {prompt:output} pairs to a “ground truth””article, stated
“The LLM Judge Agent evaluates the Generated AST and provides a score based on its alignment with the Real World AST Input.”article, stated

synthetic-data-generation (data)

Segment generated synthetic prompts from real ASTs to create evaluation examples even though the original UI-generated ASTs had no prompt text.

“To solve for the missing prompts, we built an LLM Question Generator Agent that takes a “ground truth” AST and generates a prompt.”article, stated

eval-driven-development (evaluation)

The judge score served as the scoreboard for model selection, prompt optimization, persistent memory/RAG experiments, and multi-stage architecture decisions.

“Solving this evaluation problem would provide the “scoreboard” we would use to iterate on our architecture”article, stated
“as we explore adding persistent memory via RAG. adopting a new model, or changing our prompting, we can compare the scores to determine the impact of improvements.”article, stated

Tradeoffs

Use an LLM judge rather than strict heuristics for AST quality.

Chose LLM-as-judge semantic scoring over Exact-match or rule-based comparison.

Rationale: The product needed to accept semantically equivalent ASTs whose syntax differed from the ground truth.

“Rather than define a strict set of heuristics, LLM-as-Judge asks a model (the “judge”) to evaluate, compare, and score”article, stated
“For complex audiences, AST syntax can get complex, and there are many ways to express an audience that have the same meaning and an identical result.”article, stated

Generate synthetic prompts from ASTs rather than wait for natural prompt logs.

Chose Reverse prompt generation from ground-truth ASTs over Using only naturally collected prompt-AST pairs.

Rationale: The available production data contained ASTs from UI interactions, so synthetic prompt generation made evaluation possible immediately.

“we have a large dataset of ASTs, those ASTs were generated by our UI, not via a prompt.”article, stated
“We then take the synthetic prompts as the input into the AST Generator.”article, stated

Use discrete scoring with reasoning rather than raw continuous scores.

Chose 1-5 judge score plus chain-of-thought over 0-100 continuous scoring without reasoning.

Rationale: Discrete scoring avoided collapsed continuous outputs, while reasoning made judgments easier for engineers to inspect.

“LLM tends to only output discrete values such as 0 and 100. To address this, we ask the model to provide scores on a discrete 1-5 scale”article, stated
“Implementing CoT allows the model to explain its decisions, making it easier for engineers to understand and trust the evaluation process.”article, stated

Gotchas (what bit them)

Semantic equivalence makes ordinary automated scoring misleading.

Root cause: The AST representation allows many structures to express identical audience logic.

Resolution: Use an LLM judge to compare meaning against ground truth rather than relying on exact syntax.

“there are many ways to express an audience that have the same meaning and an identical result.”article, stated
“we faced the challenge: how do we evaluate a generative AI system, when there can be an unbounded set of “right answers”?”article, stated

The evaluation dataset had outputs but lacked the natural-language inputs.

Root cause: Ground-truth ASTs came from the existing UI, not prompt-based generation.

Resolution: Reverse-generate prompts from ground-truth ASTs with a question-generator agent.

“while we have a large dataset of ASTs, those ASTs were generated by our UI, not via a prompt.”article, stated
“to construct the necessary eval set, we needed to extract prompts from the AST.”article, stated

Judge scoring needed calibration before engineers could trust it.

Root cause: Continuous scoring and unexplained judgments were not reliable enough for human comparison.

Resolution: Use discrete 1-5 scores and chain-of-thought reasoning to improve interpretability and human alignment.

“we ask the model to provide scores on a discrete 1-5 scale, with 1 being "very bad" and 5 being "perfect."”article, stated
“The LLM Judge also needs a Chain of Thought (CoT) to provide reasoning for the scores, which can improve the model's capability and facilitate human evaluation.”article, stated

Evaluation

Segment compared judge scores with human evaluation, experimented across model families and context sizes, and used the resulting scores as baselines for future optimization.

Metrics: over 90% alignment with human evaluation · gpt-4-32k-0613 score of 4.55 out of 5.0 · Claude model score of 4.02 · roughly 89% to 92% alignment improvement from CoT

3 supporting quotes
“Our LLM Judge Evaluation system has achieved over 90% alignment with human evaluation for ASTs.”article, stated
“the most potent Claude model scoring 4.02 and the gpt-4-32k-0613 model achieving the highest score of 4.55 with full score 5.0.”article, stated
“By using CoT, the alignment with human increase from roughly 89% to 92%.”article, stated

Outcomes

The article describes thousands of marketers using Segment and a large AST dataset from the existing UI, but does not provide exact dataset row counts.

3 supporting quotes
“Every day, thousands of marketers flock to Twilio Segment to build new, advanced audiences & customer journeys”article, stated
“customers are experiencing a 3x improvement in median time-to-audience creation, and a whopping 95% feature retention rate”article, stated
“these baseline scores enable us to compare future iterations & optimizations.”article, stated