fabricatio-tagging
LLM-powered tag generation for text content. Part of the Fabricatio agent framework.
Installation
This package is part of the fabricatio monorepo and can be installed as an optional dependency using either pip or uv:
pip install fabricatio[tagging]
# or
uv pip install fabricatio[tagging]
For a full installation that includes this package and all other components of fabricatio:
pip install fabricatio[full]
# or
uv pip install fabricatio[full]
Overview
fabricatio-tagging provides a Tagging mixin class that uses LLMs to generate descriptive tags from text. It accepts a single string or a list of strings and returns corresponding tag lists, driven by a configurable Handlebars template.
The package extends Propose from fabricatio-core, so any role class that mixes in Tagging gains the tagging() method alongside existing proposal capabilities.
Key Classes
Tagging (fabricatio_tagging.capabilities.tagging)
A mixin extending Propose that adds the tagging() async method.
| Method | Signature | Returns | Description |
|---|---|---|---|
tagging |
(text: str, requirement: str = "", k: int = 0, **kwargs) -> List[str] | None |
Tag list or None |
Generate tags for a single string. Returns None if generation fails. |
tagging |
(text: List[str], requirement: str = "", k: int = 0, **kwargs) -> List[List[str]] |
List of tag lists | Generate tags for multiple strings. Each inner list corresponds to one input text. |
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | List[str] |
(required) | Input text(s) to tag |
requirement |
str |
"" |
Additional constraints for tag generation |
k |
int |
0 |
Maximum number of tags per text (0 = no limit) |
**kwargs |
Unpack[LLMKwargs] |
— | Generation parameters passed to the underlying LLM |
Raises TypeError if text is neither a str nor a List[str].
TaggingConfig (fabricatio_tagging.config)
Frozen dataclass controlling which Handlebars template is used for tag generation.
| Field | Default | Description |
|---|---|---|
tagging_template |
"built-in/tagging" |
Template name resolved by TEMPLATE_MANAGER |
Access via the singleton:
from fabricatio_tagging.config import tagging_config
print(tagging_config.tagging_template)
Usage
Mixin Tagging into a role class and call tagging():
import asyncio
from fabricatio_core.capabilities.propose import Propose
from fabricatio_tagging.capabilities.tagging import Tagging
class MyRole(Propose, Tagging):
"""A role that can generate tags."""
pass
async def main():
role = MyRole(name="tagger")
# Tag a single string
tags = await role.tagging("Python is a high-level programming language.")
print(tags) # e.g. ["python", "programming", "language"]
# Tag with requirements and a cap
tags = await role.tagging(
"Rust is a systems language.",
requirement="use lowercase technical tags only",
k=3,
)
print(tags) # e.g. ["rust", "systems", "memory-safety"]
# Tag multiple strings in a batch
batch_tags = await role.tagging([
"Django is a Python web framework.",
"Tokio is an async runtime for Rust.",
])
print(batch_tags) # e.g. [["python", "web", "django"], ["rust", "async", "tokio"]]
asyncio.run(main())
The requirement parameter provides natural-language guidance to the LLM (e.g. "use single words only", "tag by topic and difficulty level"). The k parameter limits the number of tags returned per text.
Configuration
All options below are read through the fabricatio configuration chain (see the
Configuration Guide). Set them under the
[ext.tagging] table in fabricatio.toml, equivalently under
[tool.fabricatio.ext.tagging] in pyproject.toml, or via
FABRICATIO_EXT__TAGGING__<FIELD_UPPER> environment variables.
[ext.tagging]
tagging_template = "built-in/tagging"
| Option | Type | Default | Description |
|---|---|---|---|
tagging_template |
str |
"built-in/tagging" |
The template to use for tagging. |
Access at runtime: from fabricatio_tagging.config import tagging_config.
Dependencies
fabricatio-core— Core interfaces,Proposecapability, template manager, and configuration system.
No additional dependencies.
License
MIT – see LICENSE
Metadata
Release files for fabricatio-tagging 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fabricatio_tagging-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Release files / fabricatio_tagging-0.1.7-py3-none-any.whl
| Download URL | fabricatio_tagging-0.1.7-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20bc37f1a7a355ca38b68c6e7a8d6872a4a769b6cba7fe7c8f0d0352c98a70b0
|
|
BLAKE2b-256 checksum How to use checksums |
0e8d1324e748b3b581e73b3849ef74159dcde32d0cb33f1d943e511ae725ef45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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}
|