llm-sorter
A Python library that uses LLMs as comparators for semantic sorting. Sort any list by meaning, tone, complexity, urgency, or any criteria expressible in natural language. This library uses an OpenRouter API key to interface with LLM providers.
Installation
pip install llm-sorter
Requires Python 3.10+
Quick Start
from llm_sorter import LLMSorter
sorter = LLMSorter(api_key="your-openrouter-api-key")
# Sort by reading complexity
passages = [
"The quantum entanglement phenomenon demonstrates non-local correlations...",
"The cat sat on the mat.",
"Climate change affects global weather patterns in complex ways."
]
result = sorter.sort(
items=passages,
prompt="Sort by reading level, simplest first"
)
# Sort support tickets by urgency
tickets = [
"Login button color looks off",
"CRITICAL: Production database is down, all users affected",
"Would be nice to have dark mode"
]
urgent_first = sorter.sort(
items=tickets,
prompt="Sort by urgency, most critical first"
)
How It Works
llm-sorter implements merge sort with LLM-powered comparisons. Instead of numeric comparison, the model decides which of two items should come first based on your prompt.
This enables sorting by criteria that have no numeric representation: persuasiveness, professionalism, emotional intensity, policy compliance, or any semantic property. It can also enable the sorting of large lists that cannot be sorted within a single LLM call (with the tradeoff being significant more API calls, and the associated cost and latency of each call).
When to Use This
Good fit:
- Semantic/subjective ordering (urgency, quality, tone, reading level)
- No training data available — works zero-shot
- Rapid prototyping or internal tools
- Small to medium lists (n < 100-300)
- Approximate "human-like" rankings are acceptable
Examples:
- Sort writing samples by reading level
- Prioritize support tickets by urgency
- Rank answers by helpfulness
- Order reviews by sentiment strength
When NOT to Use This
Avoid when:
- You need strict determinism or reproducibility
- A simple numeric key exists (timestamps, severity levels)
- Very large n — O(n log n) API calls get expensive
Limitations
- Non-transitive comparisons: LLMs can produce A > B, B > C, C > A cycles
- Non-deterministic: Results may vary between runs
- Cost at scale: 100 items ≈ 664 comparisons, 1000 items ≈ 10,000 comparisons
- Prompt sensitivity: Small wording changes can affect results
- Potential bias: Length, style, and positional biases exist
License
MIT
Metadata
Release files for llm-sorter 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_sorter-0.1.0.tar.gz | 4.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_sorter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / llm_sorter-0.1.0.tar.gz
| Download URL | llm_sorter-0.1.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0022e7e3112f35329144e8c5d8a77b9ebb4d6ffb1c243dacc6994ca41ef68d3d
|
|
BLAKE2b-256 checksum How to use checksums |
6842a7a65996f97472da18e56abb06b552138ebdafcc1736739599e7027e6fce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / llm_sorter-0.1.0-py3-none-any.whl
| Download URL | llm_sorter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
963038aed4d3d7f0213c4de9fc26c0f95435098a80c3bd975348b3f1c3e67b18
|
|
BLAKE2b-256 checksum How to use checksums |
3df6f7923e80b2a1ec806a30aa78189f269d7b4ff01c7e5b974c6493439f3a33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for llm-sorter 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.