Skip to content
Back to skills

Grading

ASecurity

Evaluates document relevance to queries using binary scoring (yes/no) with reasoning. Use when filtering retrieved documents, determining relevance for answer generation, or when the user mentions grading, filtering, or document quality.

  • 666 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 8, 2026
developmentpythonapi

Works with

  • api

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill grading --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Grading?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Grading
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-grading/badge)](https://www.skillsdirectory.com/skills/majiayu000-grading)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: grading
description: Evaluates document relevance to queries using binary scoring (yes/no) with reasoning. Use when filtering retrieved documents, determining relevance for answer generation, or when the user mentions grading, filtering, or document quality.
---

# Document Grading

## Instructions

Grade documents for relevance using the functions in `components/grader.py`. The grading uses Claude API with structured outputs for consistent binary decisions.

**Default workflow:**

1. Retrieve documents from ChromaDB or web search
2. Call `grade_documents(query, documents)` to grade all documents
3. Call `filter_relevant_documents(graded_docs)` to get only relevant ones
4. Check if `len(relevant_docs) == 0` to trigger retry logic

**Key functions:**

```python
# Grade multiple documents (preferred)
graded_docs = grade_documents(query, documents)

# Filter to relevant only
relevant_docs = filter_relevant_documents(graded_docs)

# Grade single document (if needed)
result = grade_document(query, document)
```

**Grading returns:**
- `relevant`: Boolean (True/False)
- `reasoning`: Explanation of decision

**Critical for adaptive retry:** When ALL documents are graded as not relevant (`len(relevant_docs) == 0`), the pipeline triggers query rewriting and retry.

**Implementation:** `components/grader.py`, uses `GRADING_MODEL` from `config.py` (default: Haiku 4.5), temperature 0.

## Examples

### Example 1: Standard grading workflow

```python
from components.grader import grade_documents, filter_relevant_documents
from tools.chromadb_tool import query_chromadb

# Input
docs = query_chromadb("gaming laptops", top_k=5)
# Retrieved: 5 documents from catalog

# Grade
graded = grade_documents("gaming laptops", docs)
relevant = filter_relevant_documents(graded)

# Output
# Found 3 relevant documents out of 5 total
# Each has grading_result: {relevant: True, reasoning: "..."}
```

### Example 2: Triggering retry

```python
# Input: Vague query
docs = query_chromadb("fast computer", top_k=5)
graded = grade_documents("fast computer", docs)
relevant = filter_relevant_documents(graded)

# Output
# len(relevant) == 0
# → Triggers query rewrite and retry
```

### Example 3: In adaptive RAG pipeline

```python
# After retrieval
graded_documents = grade_documents(current_query, retrieved_documents)
relevant_documents = filter_relevant_documents(graded_documents)

if len(relevant_documents) == 0:
    # No relevant docs - rewrite query and retry
    if num_retries < RETRY_LIMIT:
        rewrite_result = rewrite_query(current_query, previous_context)
        current_query = rewrite_result['rewritten_query']
        num_retries += 1
        # Loop back to retrieval
else:
    # Found relevant docs - proceed to generation
    generate_answer(original_query, relevant_documents)
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.