The user wants a "human annotation feedback UI for LLM responses."
Key requirements:
- Target: LLM Responses (Chat interface context usually).
- Features:
- Rating Rubrics (Likert scales, stars, specific criteria).
- Notes (Free-form text input).
- Active Learning (Mechanisms to flag for retraining, suggest edits, or select specific spans).
Target Audience: Data scientists, RLHF (Reinforcement Learning from Human Feedback) teams, QA testers for LLMs.
Tech Stack:
- Framework: React (most common for this type of interactive UI).
- Styling: Tailwind CSS (for rapid, clean prototyping).
- State Management: React
useState (sufficient for a component demo).
Component Structure:
ConversationView: Displays the prompt and the LLM response.
AnnotationPanel: The core interaction area.
- Sub-component:
RatingSystem (Rubrics).
- Sub-component:
FeedbackNotes (Text area).
- Sub-component:
ActiveLearningControls (Edit suggestion, flagging).
Design Thinking (UX/UI):
- Layout: Split view or bottom sheet? A sidebar or a collapsible section under the response is usually best to keep context. Let's go with a clean card design where the message is on top, and the annotation tools are below.
- Rubrics: Instead of just "Good/Bad", let's use dimensions: Truthfulness, Helpfulness, Safety. This mimics real RLHF workflows.
- Active Learning: Needs a way to "Select text to annotate". This is crucial. If I click a sentence in the response, I should be able to flag that specific part.
- Visual Feedback: Needs to look professional, not like a generic form. Dark mode is popular in developer tools.
Step-by-Step Implementation Plan:
- Mock Data: Create a sample conversation (User Prompt -> Assistant Response).
- Main Container: A clean wrapper.
- Message Display:
- Show the User Prompt (muted).
- Show the Assistant Response (highlighted).
- Feature: Allow text selection on the Assistant response for specific feedback.
- Annotation Sidebar/Section:
- Rubrics: 1-5 Star or Thumbs system. Let's do a 5-point scale for specific attributes (Accuracy, Tone, Safety).
- Notes: Textarea.
- Active Learning:
- "Reasoning" check.
- "Suggested Edit" field (Gold standard response).
- "Flag for Training" toggle.
- Interactivity:
- Handling text selection (getting the substring).
- Submit handler (logging the JSON object to console).
Refining the "Active Learning" aspect:
Active learning usually implies selecting the most valuable data points to label next. In an annotation UI, this often translates to uncertainty sampling visualized (e.g., the model says "I'm not sure, please check") OR the human providing the "Gold Response" to teach the model. I will focus on the human providing the gold response and correcting the model aspect, as that is the input side of active learning.
Drafting the Code Structure (Mental or Scratchpad):
// Data Structure
const annotation = {
rating: { accuracy: 0, tone: 0 },
notes: "",
selectedSpan: null,
suggestedCorrection: "",
category: "good" | "bad"
}
Refining the UI:
Let's make it look like a VS Code extension or a dashboard widget.
- Dark theme.
- Monospace font for the response.
- Sans-serif for UI elements.
Specific Feature: Text Selection:
When the user highlights text in the LLM response, a small tooltip pops up: "Analyze Selection". Clicking it adds that text to the activeLearning section so the user can explain why that specific part is wrong.
Let's write the code.
- Self-Correction during drafting: A full React app setup is too much boilerplate. I will provide a single file (or logical breakdown) that can be dropped into a project, using standard Tailwind classes. I'll assume Tailwind is available or write inline styles if needed, but Tailwind is better for "Engineering". I will provide a React component.
Code sections:
ConversationThread: The prompt/response.
AnnotationWidget: The controls.
MetricSlider: For the rubric.
CorrectionInput: For active learning.
Let's polish the Rubric part. Instead of just stars, let's use a matrix or sliders. Sliders are faster for mouse users.
Active Learning detail:
Include a "Rank" or "Priority" selector. Is this an easy example or a hard edge case? This helps the active learning backend prioritize.
Final Output Generation:
I will provide a high-quality React component with Tailwind CSS classes. I will simulate the data handling.
Check: Did I include all constraints?
- Rubrics? Yes (sliders/stars).
- Notes? Yes (textarea).
- Active Learning? Yes (text selection + correction).
Let's build it.
UI Layout:
[ User Prompt ]
[ Assistant Response (Selectable) ]
[ Annotation Panel ]
[ Rubric Section (Accuracy, Coherence) ]
[ Active Learning Section (Span Feedback, Suggested Edit) ]
[ General Notes ]
[ Submit ]
I will add comments explaining why specific UI choices were made (e.g., why sliders vs stars for granular data).
Code specifics:
Use window.getSelection() logic for the active learning text span feature.
Let's go.
This is a comprehensive solution engineered as a React Component (with Tailwind CSS for styling). It is designed to be dropped into a data labeling pipeline or an internal evaluation tool.
Design Philosophy
- Context-Centric: The UI keeps the LLM response visible alongside the grading interface to reduce context switching.
- Granularity: It supports both holistic scoring (0-5 stars) and specific span-based feedback (highlighting text).
- Active Learning Ready: It captures the "Gold Response" (ground truth), allowing you to use this data for Fine-Tuning (SFT) or RLHF.
The Component Architecture
import React, { useState, useEffect } from 'react';
// Icons (Using simple SVGs for portability)
const IconStar = ({ filled }) => (
<svg className={`w-6 h-6 ${filled ? 'text-yellow-400' : 'text-gray-600'}`} fill="currentColor" viewBox="0 0 20 20">
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
</svg>
);
const IconCheck = () => (
<svg className="w-5 h-5 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M5 13l4 4L19 7" />
</svg>
);
const AnnotationUI = ({ responseData, onSubmit }) => {
// --- State Management ---
const [rubricScores, setRubricScores] = useState({});
const [generalNotes, setGeneralNotes] = useState('');
const [correctedText, setCorrectedText] = useState('');
const [flags, setFlags] = useState([]);
const [selectionMeta, setSelectionMeta] = useState(null);
const [activeLearningTag, setActiveLearningTag] = useState('neutral');
// --- Rubric Definitions (Configurable) ---
const rubrics = [
{ id: 'truthfulness', label: 'Truthfulness', description: 'Is the factually correct?' },
{ id: 'helpfulness', label: 'Helpfulness', description: 'Did it solve the users problem?' },
{ id: 'tone', label: 'Tone & Style', description: 'Is the tone appropriate and professional?' },
];
const flagOptions = [
{ id: 'hallucination', label: 'Hallucination', color: 'bg-red-900/50 border-red-500' },
{ id: 'bias', label: 'Bias', color: 'bg-orange-900/50 border-orange-500' },
{ id: 'safety', label: 'Safety Issue', color: 'bg-red-800/50 border-red-600' },
];
// --- Interaction Handlers ---
// Handle Text Selection for Span Annotation
const handleMouseUp = () => {
const selection = window.getSelection();
if (selection.toString().length > 0) {
const range = selection.getRangeAt(0);
const rect = range.getBoundingClientRect();
// Calculate position relative to the container for the popup
const containerRect = document.getElementById('response-container').getBoundingClientRect();
setSelectionMeta({
text: selection.toString(),
top: rect.bottom - containerRect.top + 5, // 5px buffer
left: rect.left - containerRect.left + (rect.width / 2),
start: selection.anchorOffset,
end: selection.focusOffset
});
} else {
// Delay hiding to allow click events inside the popup to register
setTimeout(() => setSelectionMeta(null), 100);
}
};
const annotateSelection = (type) => {
// In a real app, you would wrap the text in <span> tags here.
// For this demo, we add it to a list of findings.
setGeneralNotes(prev => `${prev}\n[Annotation "${type}"]: "${selectionMeta.text}"`);
setSelectionMeta(null);
};
const handleRating = (rubricId, score) => {
setRubricScores(prev => ({ ...prev, [rubricId]: score }));
};
const toggleFlag = (flagId) => {
setFlags(prev =>
prev.includes(flagId) ? prev.filter(f => f !== flagId) : [...prev, flagId]
);
};
// --- Submit Handler ---
const handleSubmit = () => {
const payload = {
id: responseData.id,
timestamp: new Date().toISOString(),
metrics: {
rubrics: rubricScores,
flags: flags,
active_learning_tag: activeLearningTag
},
text_feedback: {
notes: generalNotes,
gold_response: correctedText
}
};
// Callback to parent
if(onSubmit) onSubmit(payload);
// Visual feedback (in real app, use a toast)
alert('Annotation Submitted! Check console for JSON structure.');
console.log(payload);
};
return (
<div className="min-h-screen bg-gray-900 text-gray-100 font-sans flex flex-col md:flex-row gap-6 p-6">
{/* Left Column: The Response (Read Only) */}
<div className="flex-1 bg-gray-800 rounded-xl shadow-2xl border border-gray-700 overflow-hidden flex flex-col">
<div className="p-4 border-b border-gray-700 bg-gray-800/50 flex justify-between items-center">
<h2 className="text-sm font-bold text-gray-400 uppercase tracking-wider">Model Response</h2>
<span className="text-xs bg-blue-900 text-blue-300 px-2 py-1 rounded">GPT-4-Turbo</span>
</div>
<div
id="response-container"
className="p-6 text-lg leading-relaxed text-gray-200 relative flex-1 overflow-auto"
onMouseUp={handleMouseUp}
>
{responseData.content}
{/* Floating Annotation Toolbar (Active Learning) */}
{selectionMeta && (
<div
className="absolute z-50 flex gap-2 bg-gray-700 p-2 rounded-lg shadow-xl border border-gray-600 transform -translate-x-1/2"
style={{ top: `${selectionMeta.top}px`, left: `${selectionMeta.left}px` }}
>
<button
onClick={() => annotateSelection('Fact Error')}
className="px-3 py-1 text-xs bg-red-600 hover:bg-red-500 rounded text-white font-semibold"
>
Fact Error
</button>
<button
onClick={() => annotateSelection('Unclear')}
className="px-3 py-1 text-xs bg-yellow-600 hover:bg-yellow-500 rounded text-white font-semibold"
>
Unclear
</button>
<button
onClick={() => annotateSelection('Harmful')}
className="px-3 py-1 text-xs bg-purple-600 hover:bg-purple-500 rounded text-white font-semibold"
>
Harmful
</button>
</div>
)}
</div>
</div>
{/* Right Column: Feedback Interface */}
<div className="w-full md:w-[400px] flex flex-col gap-6">
{/* 1. Rubrics Section */}
<div className="bg-gray-800 rounded-xl p-5 border border-gray-700">
<h3 className="text-lg font-bold mb-4 text-white">Evaluation Rubrics</h3>
<div className="space-y-5">
{rubrics.map((rubric) => (
<div key={rubric.id}>
<div className="flex justify-between items-center mb-1">
<label className="font-medium text-gray-300">{rubric.label}</label>
<div className="flex">
{[1, 2, 3, 4, 5].map((star) => (
<button
key={star}
onClick={() => handleRating(rubric.id, star)}
className="focus:outline-none"
>
<IconStar filled={(rubricScores[rubric.id] || 0) >= star} />
</button>
))}
</div>
</div>
<p className="text-xs text-gray-500">{rubric.description}</p>
</div>
))}
</div>
</div>
{/* 2. Quick Flags (Active Learning Tags) */}
<div className="bg-gray-800 rounded-xl p-5 border border-gray-700">
<h3 className="text-lg font-bold mb-4 text-white">Classification Tags</h3>
<div className="flex flex-wrap gap-2">
{flagOptions.map((flag) => (
<button
key={flag.id}
onClick={() => toggleFlag(flag.id)}
className={`px-3 py-1.5 rounded-full text-sm font-medium border transition-all duration-150
${flags.includes(flag.id)
? `${flag.color} text-white scale-105 shadow-lg`
: 'bg-gray-700 border-gray-600 text-gray-400 hover:bg-gray-600'}`}
>
{flags.includes(flag.id) && <IconCheck />} {flag.label}
</button>
))}
</div>
</div>
{/* 3. Active Learning / Gold Response */}
<div className="bg-gray-800 rounded-xl p-5 border border-gray-700">
<h3 className="text-lg font-bold mb-4 text-white">Active Learning & Correction</h3>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-400 mb-2">Priority for Training</label>
<div className="flex gap-2">
{['low', 'neutral', 'high'].map((lvl) => (
<button
key={lvl}
onClick={() => setActiveLearningTag(lvl)}
className={`flex-1 py-2 rounded text-xs font-bold uppercase tracking-wider border transition-all
${activeLearningTag === lvl
? 'bg-blue-600 border-blue-500 text-white'
: 'bg-gray-700 border-gray-600 text-gray-400 hover:border-gray-500'}`}
>
{lvl}
</button>
))}
</div>
</div>
<label className="block text-sm font-medium text-gray-400 mb-2">Corrected Response (Gold)</label>
<textarea
className="w-full bg-gray-900 border border-gray-600 rounded-lg p-3 text-sm text-gray-200 focus:ring-1 focus:ring-blue-500 outline-none min-h-[100px]"
placeholder="If the model was wrong, paste the ideal response here for SFT..."
value={correctedText}
onChange={(e) => setCorrectedText(e.target.value)}
/>
</div>
{/* 4. General Notes */}
<div className="bg-gray-800 rounded-xl p-5 border border-gray-700">
<label className="block text-sm font-medium text-gray-400 mb-2">Annotator Notes</label>
<textarea
className="w-full bg-gray-900 border border-gray-600 rounded-lg p-3 text-sm text-gray-200 focus:ring-1 focus:ring-blue-500 outline-none min-h-[80px]"
placeholder="Internal notes, edge case descriptions..."
value={generalNotes}
onChange={(e) => setGeneralNotes(e.target.value)}
/>
</div>
{/* Submit */}
<button
onClick={handleSubmit}
className="w-full bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white font-bold py-3 px-4 rounded-lg shadow-lg transition-all transform hover:scale-[1.02]"
>
Submit Feedback
</button>
</div>
</div>
);
};
// --- Demo Usage ---
// This data would typically come from your database
const mockData = {
id: 'resp_8923',
content: "To integrate a REST API, you first need to fetch the endpoint. Usually, this is done via a GET request. Note that GraphQL is often better for graph data structures. Also, always handle errors gracefully."
};
export default function App() {
return (
<div className="min-h-screen bg-gray-950 p-4">
<AnnotationUI
responseData={mockData}
onSubmit={(data) => console.log("Submitted Payload:", data)}
/>
</div>
);
}
Engineering Features Breakdown
-
Rubric Rating System:
- We use a 5-star system mapped to specific dimensions (Truthfulness, Helpfulness, Tone).
- Engineering Note: This is stored in an object state
{ truthfulness: 4, helpfulness: 2 }, ready for aggregation into backend metrics.
-
Text Selection & Active Learning (Span Annotation):
- We listen for
onMouseUp on the response container.
- Using
window.getSelection(), we calculate the bounding box.
- A floating toolbar appears directly over the selected text. This is crucial for "in-context" labeling without scrolling.
-
Classification Tags (Boolean Flags):
- The chips allow for quick binary classification (e.g., Is this a hallucination?).
- The state handles arrays, allowing multiple tags per response.
-
The "Gold Response" Field:
- Located at the bottom, this allows the human to rewrite the model's answer.
- Why this matters: If the model failed, this text box provides the Supervised Fine-Tuning (SFT) data required to fix the model in the next training run.
-
Data Payload:
- The
handleSubmit function constructs a clean JSON object containing:
rubrics: Quantitative scores.
flags: Categorical tags.
active_learning_tag: "High" priority items are prioritized in the next batch.
gold_response: The corrected ground truth.