A Python module for rule-based content validation, correction, and enforcement in LLM applications.
Project description
fabricatio-rule
A Python module for rule-based content validation, correction, and enforcement in LLM applications.
📦 Installation
This package is part of the fabricatio monorepo and can be installed as an optional dependency:
pip install fabricatio[rule]
Or install all components:
pip install fabricatio[full]
🔍 Overview
Provides robust tools for defining, applying, and enforcing rulesets across text and structured objects. Combines capabilities from multiple packages to offer:
- Rule generation based on natural language requirements
- Content validation against rulesets
- Automatic correction suggestions
- Censoring/filtering of content
Key Features:
- Asynchronous execution support
- Structured rule definition format
- Evidence-based judgment integration
- Content correction workflows
- Multiple input types (strings, Display/WithBriefing objects)
🧩 Usage Example
from fabricatio_rule.actions.rules import DraftRuleSet
from fabricatio_rule.capabilities.censor import Censor
from fabricatio_rule.models.rule import RuleSet
class MyCensor(Censor):
pass # Implement custom logic if needed
async def example():
# Generate a ruleset
draft_action = DraftRuleSet(ruleset_requirement="Professional tone and grammar")
ruleset: RuleSet = await draft_action._execute()
# Use censor to validate and correct content
censor = MyCensor()
result = await censor.censor_string(
"Ths is a verry bad exmple of txt.",
ruleset
)
print(f"Corrected text: {result}")
📁 Structure
fabricatio-rule/
├── actions/
│ └── rules.py - Rule set drafting/gathering actions
├── capabilities/
│ ├── check.py - Core rule checking functionality
│ └── censor.py - Content filtering/correction capabilities
└── models/
├── kwargs_types.py - Validation argument types
├── patch.py - Metadata patching utilities
└── rule.py - Rule/RuleSet definitions
🔗 Dependencies
Built on top of other Fabricatio modules:
fabricatio-core- Core interfaces and utilitiesfabricatio-improve- Correction suggestion mechanismsfabricatio-judge- Evidence-based decision makingfabricatio-capabilities- Base capability patterns
📄 License
MIT – see LICENSE
GitHub: github.com/Whth/fabricatio
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fabricatio_rule-0.1.2.dev11-py3-none-any.whl.
File metadata
- Download URL: fabricatio_rule-0.1.2.dev11-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a035f56bae2a7fb181f04b7caaceb49060f142d01cc2a50592ccd3975fb750
|
|
| MD5 |
c1ad0494e007ae68a3a3764623051ad3
|
|
| BLAKE2b-256 |
4761c7034cdc589c8f57204af0d4539f4da33190267e173e44c033e66978e8f4
|