Swarmauri Tool · Text Length
A Swarmauri-ready helper that measures text length in characters, words, and sentences using NLTK tokenization. Drop it into content pipelines, moderation bots, or editorial agents to monitor message size and cadence.
- Counts characters (excluding spaces) for quick size checks.
- Uses NLTK tokenizers to calculate word and sentence totals accurately.
- Returns a structured dictionary suitable for logging, analytics, or conversational outputs.
Requirements
- Python 3.10 – 3.13.
nltkwith thepunkt_tabresource available (downloaded automatically on import).- Core Swarmauri dependencies (
swarmauri_base,swarmauri_standard,pydantic).
Installation
Pick the packaging tool that fits your workflow; each command installs dependencies.
pip
pip install swarmauri_tool_textlength
Poetry
poetry add swarmauri_tool_textlength
uv
# Add to the current project and update uv.lock
uv add swarmauri_tool_textlength
# or install into the active environment without editing pyproject.toml
uv pip install swarmauri_tool_textlength
Tip: When building containers or offline environments, pre-fetch NLTK data with
python -m nltk.downloader punkt_tabto avoid runtime downloads.
Quick Start
from swarmauri_tool_textlength import TextLengthTool
text = "This is a simple test sentence."
length_tool = TextLengthTool()
result = length_tool(text)
print(result)
# {
# 'num_characters': 26,
# 'num_words': 7,
# 'num_sentences': 1
# }
Usage Scenarios
Enforce Message Length in Moderation Bots
from swarmauri_tool_textlength import TextLengthTool
length_checker = TextLengthTool()
message = """Please keep replies under 50 words so the queue stays manageable."""
metrics = length_checker(message)
if metrics["num_words"] > 50:
raise ValueError("Message too long for moderation queue")
Provide Real-Time Feedback in a Swarmauri Agent
from swarmauri_core.agent.Agent import Agent
from swarmauri_core.messages.HumanMessage import HumanMessage
from swarmauri_standard.tools.registry import ToolRegistry
from swarmauri_tool_textlength import TextLengthTool
registry = ToolRegistry()
registry.register(TextLengthTool())
agent = Agent(tool_registry=registry)
message = HumanMessage(content="Analyze how long this paragraph is compared to our guideline.")
response = agent.run(message)
print(response)
Batch Audit Documentation for Sentence Length
from pathlib import Path
from swarmauri_tool_textlength import TextLengthTool
length_tool = TextLengthTool()
for doc in Path("docs").rglob("*.md"):
metrics = length_tool(doc.read_text(encoding="utf-8"))
print(f"{doc}: {metrics['num_sentences']} sentences, {metrics['num_words']} words")
Scan an entire documentation set to identify sprawling sections or under-documented topics.
Troubleshooting
LookupError: Resource punkt_tab not found– Runpython -m nltk.downloader punkt_tabahead of time, especially in air-gapped deployments.- Unexpected character counts – The tool excludes spaces; adjust the implementation if you need raw length including whitespace.
- Non-English text – NLTK’s default tokenizers target English. Swap in language-specific tokenizers if needed.
License
swarmauri_tool_textlength is released under the Apache 2.0 License. See LICENSE for full details.
Metadata
Release files for swarmauri_tool_textlength 0.9.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 | Actions |
|---|---|---|---|---|
| swarmauri_tool_textlength-0.9.0.tar.gz | 8.0 kB | Without provenance | Details for swarmauri_tool_textlength-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_tool_textlength-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_tool_textlength-0.9.0-py3-none-any.whl |
Total release size: 17.0 kB
Release files / swarmauri_tool_textlength-0.9.0.tar.gz
| Download URL | swarmauri_tool_textlength-0.9.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b8cdc16a9df3aa6c44c938282a74751ddffed103f2c3283aae11b567ac4dbe5
|
|
BLAKE2b-256 checksum How to use checksums |
f267a0ea141846ab718e3e480f5d7d0bcd76c0f42cc417d4f1389f2a13e2186b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_tool_textlength-0.9.0-py3-none-any.whl
| Download URL | swarmauri_tool_textlength-0.9.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a743c064f078b7d1874e149f4305bf3ef18818447106723ce26e06ed08874fba
|
|
BLAKE2b-256 checksum How to use checksums |
6231fee50ad1bfbb101fca12d96c694a104ff2c5b6c5560ea752a1cb15c57253
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_tool_textlength 0.9.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.