Skip to main content

LLM-powered decorators for intelligent function behavior

Project description

Mores

LLM-powered Python decorators for intelligent function behavior. Add validation, mocking, and output checking to your functions with a single line of code.

Installation

{pip, uv} install mores

Setup

Configure

export MORES_API_KEY=gsk_your_key_here
export MORES_SERVER_URL=https://mores.fulcrumresearch.ai

Decorators

All decorators support two modes, depending on latency and intelligence requirements, passed in as keyword arguments - mode=fast and mode=slow.

@guard - Pre-execution Validation

Validates function calls against custom rules before execution.

Basic Usage:

@guard(rules=[
    "Never allow deletion",
    "Only allow amounts under 100"
])
def transfer(amount: float, delete: bool = False):
    """Transfer an amount."""
    if delete:
        return "deleted"
    return f"transferred {amount}"

result = transfer(50, delete=False)  # ✓ Returns Value
result = transfer(200, delete=False)  # ✗ Returns Rejected
result = transfer(50, delete=True)   # ✗ Returns Rejected

Processing Guard Results:

By default, @guard returns a Maybe type (either Value or Rejected). You can handle this in the following way.

  1. Pattern matching with match/case (default):
result = transfer(50, delete=False)
match result:
    case Value(data=data):
        # Function executed successfully
        print(f"Success: {data}")
    case Rejected(reason=reason):
        # Call was rejected
        print(f"Error: {reason}")

You can also @guard(..., raise_reject=True) to return the raw output, and raise if an error is caught.

@mock - LLM-Generated Output

Replaces function execution with AI-generated mock output based on the function signature and documentation.

from mores import mock

@mock()
def calculate_fibonacci(n: int):
    """Calculate the nth Fibonacci number."""
    pass  # Implementation doesn't matter

result = calculate_fibonacci(10)
print(result)  # LLM-generated Fibonacci number

@doubt - Post-execution Validation

Validates that function output is correct given its inputs and implementation. Raises DoubtError if the output appears incorrect.

from mores import doubt, DoubtError

@doubt()
def add(a: int, b: int):
    """Add two numbers."""
    return a + b

# Correct implementation passes
result = add(2, 3)  # Returns 5, no error

# Incorrect implementation raises error
@doubt()
def broken_add(a: int, b: int):
    """Add two numbers."""
    return a * b  # Wrong! Multiplying instead

try:
    broken_add(2, 3)
except DoubtError as e:
    print(e.reason)  # "The function should add but it's multiplying..."

Project details


Download files

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

Source Distribution

mores-0.1.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

mores-0.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file mores-0.1.2.tar.gz.

File metadata

  • Download URL: mores-0.1.2.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for mores-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4cf73b83037086d08191cd7bf810d5467749edf88796d36ac89a295c044a4baa
MD5 b82c6378f97676faa31229e5d658cc52
BLAKE2b-256 2e7b64f9ca09919d3e523998e32795acad4eb445594bef73dd7b25ecbe2c76b0

See more details on using hashes here.

File details

Details for the file mores-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mores-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for mores-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ef49d2aed71710535fcd0998aec1bccab5fb319fb179d1c3d9bf59e327e8f4f
MD5 abb5509982984dc8375ccbad6272a145
BLAKE2b-256 57c94307fabb3b293a7b230e38330d43da6b2061a7d7dff6bbe89e8fdd5fdfeb

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