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.3.dev1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_rule-0.1.3.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for fabricatio_rule-0.1.3.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 76cf948eef5a30390bddd148c5cf13612f5f84df08af40c85bc807c55214ce31
MD5 d8df771ed2d7c999294c1d469e79bb18
BLAKE2b-256 7e99d4796204cbbbb9acf044473cbddfe8fd170aaea8cf2a1b021b70dc4d6b7c

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