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.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file fabricatio_rule-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fabricatio_rule-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3c7f4cb4c1e602703bccc81e9eb0d6cf12f7d47ab0e93a529d0ba5fdb0dd48d6
MD5 04be541b5b447f81182a3d64ff37b42f
BLAKE2b-256 cee4c3436e314cd92f8e3730e8273fe2987994cca0a5ddcd3c768c888f376fce

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