Skip to main content

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 utilities
  • fabricatio-improve - Correction suggestion mechanisms
  • fabricatio-judge - Evidence-based decision making
  • fabricatio-capabilities - Base capability patterns

📄 License

MIT – see LICENSE

GitHub: github.com/Whth/fabricatio

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fabricatio_rule-0.1.2.dev4-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_rule-0.1.2.dev4-py3-none-any.whl.

File metadata

File hashes

Hashes for fabricatio_rule-0.1.2.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 8957e6f2d49238d4d5837bf02c03e25f1b37d95829e38f484ae03f0d7f27f71c
MD5 d6475235fee95e1cb205304fe7e5e943
BLAKE2b-256 e99bd2e04b455c7e21f651ff703ad0e44b2d34b8b122a1d8d4ce329753ca4677

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page