
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
scope-classifier
Advanced tools
Given the specifications of an AI assistant and a user query, scope-classifier classifies the user query into one of the following five classes:
Currently, the following models are supported:
| Model | Parameters | Description | Accuracy | Required VRAM | Relative Speed |
|---|---|---|---|---|---|
small (or edobobo/cernas-qwen3-1.7B-v0.4) | 1.7B | A compact and fast model for general use. | 85.3 | 8GB | 1x |
medium (or (mocked) organization/medium-model-7B) | 7B | A larger model with better performance. | 90.7 | 12GB | 0.75x |
large (or (mocked) organization/large-model-13B) | 13B | The best performing model for complex tasks. | 94.2 | 24GB | 0.5x |
Install scope-classifier:
pip install scope-classifier[vllm]
Then:
from scope_classifier import ScopeClassifier
# Initialize the classifier
classifier = ScopeClassifier(
"vllm", # backend (or use "hf" if you prefer not to use vllm)
"small" # model
)
# Define the AI assistant's scope
ai_service_description = (
"You are a virtual assistant for a parcel delivery service. "
"You can only answer questions about package tracking. "
"Never respond to requests for refunds."
)
# Classify a user's query
user_query = "If the package hasn't arrived by tomorrow, can I get my money back?"
classification_output = classifier.classify(user_query, ai_service_description)
print(f"Scope: {classification_output.scope_class.value}")
if classification_output.evidences:
print("Evidences:")
for evidence in classification_output.evidences:
print(f" - {evidence}")
Internally, scope-classifier works by prompting local LLMs on your data. To do this, we currently support two possible backends:
hf): Uses HuggingFace pipelines, ideal for offline processingvllm): Faster version using vLLM, strongly encouraged for better performanceWhile hf comes always bundled with scope-classifier, you need to install some more dependencies to use vllm:
pip install scope-classifier[vllm]
IMPORTANT: these two backends are local, meaning no external API call, no data leaving your network
The classify method is flexible and accepts various input formats for the conversation.
As shown in the Quick Start, you can pass the user query as a simple string.
classification_output = classifier.classify(
"When is my package scheduled to arrive?",
ai_service_description
)
You can also provide the user query in a dictionary format, similar to OpenAI's API:
classification_output = classifier.classify(
{"role": "user", "content": "When is my package scheduled to arrive?"},
ai_service_description
)
Note that the role must be "user".
For multi-turn conversations, you can pass a list of messages:
conversation_history = [
{"role": "user", "content": "I ordered a package, tracking number 1234567890"},
{"role": "assistant", "content": "Great, the package is in transit. What would you like to know?"},
{"role": "user", "content": "If it doesn't arrive tomorrow, can I get a refund?"},
]
classification_output = classifier.classify(conversation_history, ai_service_description)
The classifier will always consider the last user message for scope classification.
You can classify multiple conversations at once using batch_classify.
Classify multiple user queries against the same AI service description:
queries = [
"If the package hasn't arrived by tomorrow, can I get my money back?",
"When is the package expected to be delivered?"
]
classification_outputs = classifier.batch_classify(
queries,
ai_service_description=ai_service_description
)
for i, output in enumerate(classification_outputs):
print(f"--- Query {i+1} ---")
print(f"Scope: {output.scope_class.value}")
if output.evidences:
print("Evidences:")
for evidence in output.evidences:
print(f" - {evidence}")
You can also provide a different AI service description for each conversation:
ai_service_descriptions = [
"You are a virtual assistant for Postal Service. You only answer questions about package tracking. Never respond to refund requests.",
"You are a virtual assistant for a Courier. You answer questions about package tracking. Never respond to refund requests."
]
classification_outputs = classifier.batch_classify(
queries,
ai_service_descriptions=ai_service_descriptions
)
# Process outputs...
The AI service description can be provided in two ways:
scope_classifier.modeling.AIServiceDescription. This is the recommended approach.The AIServiceDescription object has the following fields:
identity_role (str): The identity, role, and objectives of the AI Service.context (str): The context in which the AI Service operates (e.g., company, sector).functionalities (str): The functionalities provided by the AI Service.knowledge_scope (str): The scope of knowledge and expertise of the AI Service.conduct_guidelines (str): Conduct guidelines and principles followed by the AI Service.constraints (str): Constraints and limitations of the AI Service.fallback (str): Fallback mechanisms for out-of-scope requests.website_url (str, optional): The URL of the AI Service's website.Using the structured format allows the underlying model to better understand the nuances of your AI assistant's scope and, therefore, perform better.
The examples/simple.py script demonstrates a basic use of the ScopeClassifier. It provides an example of how to classify a user query based on the AI service description using command-line arguments.
python examples/simple.py vllm small
The script will print the classification results and evidences extracted from the AI description:
# scope: Restricted
# evidences:
* evidence: Non rispondere mai a richieste di rimborso.
# time: X.XX seconds
scope-classifier comes with built-in support for serving. For better performance, it consists of two components:
All of this is setup via the scope-classifier serve command:
# install the necessary packages
pip install scope-classifier[serve]
# start everything
scope-classifier serve small --port 8000
Once the server is running, you can interact with it as follows:
Send requests to the /api/n/scope-classifier/classify (or /api/in/scope-classifier/batch-classify) endpoint using cURL or any HTTP client:
curl -X 'POST' \
'http://localhost:8000/api/in/scope-classifier/classify' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"conversation": "If the package doesn''t arrive by tomorrow, can I get my money back?",
"ai_service_description": "You are a virtual assistant for a parcel delivery service. You can only answer questions about package tracking. Never respond to requests for refunds."
}'
Response:
{
"evidences": [
"Never respond to requests for refunds."
],
"scope_class": "Restricted",
"time_taken": 0.23,
"model": "small"
}
scope-classifier comes with built-in SDKs to invoke the server directly from Python. These SDKs support both synchronous and asynchronous invocations:
Synchronous API client:
from scope_classifier import ScopeClassifier
classifier = ScopeClassifier(
"api", # backend
"http://localhost:8000" # API URL
)
result = classifier.classify(
"If the package doesn't arrive by tomorrow, can I get my money back?",
"You are a virtual assistant for a parcel delivery service. You can only answer questions about package tracking. Never respond to requests for refunds."
)
print(f"Scope: {result.scope_class.value}")
Asynchronous API client:
For async usage, use the AsyncScopeClassifier with the async backend and await the classify calls:
from scope_classifier import AsyncScopeClassifier
classifier = AsyncScopeClassifier(
"async", # backend
"http://localhost:8000" # API URL
)
result = await classifier.classify(
"If the package doesn't arrive by tomorrow, can I get my money back?",
"You are a virtual assistant for a parcel delivery service. You can only answer questions about package tracking. Never respond to requests for refunds."
)
print(f"Scope: {result.scope_class.value}")
This project is licensed under the Apache 2.0 License.
FAQs
A scope classification library around your prompts
We found that scope-classifier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.