Skip to main content

lexigram-ai-feedback

AI feedback collection for the Lexigram Framework — collection, processing, and storage


Overview

AI feedback collection and continuous-learning loop for the Lexigram Framework. Captures user ratings, corrections, text feedback, and ground-truth labels from LLM interactions and routes them through an extensible processor pipeline to configurable storage backends. Zero-config usage starts with sensible defaults.

Full documentation: docs.lexigram.dev

Install

uv add lexigram-ai-feedback

Quick Start

from lexigram import Application
from lexigram.di.module import Module, module

from lexigram.ai.feedback import FeedbackModule
from lexigram.ai.feedback.config import FeedbackConfig


@module(
    imports=[
        FeedbackModule.configure(
            FeedbackConfig(
                enabled=True,
                async_processing=True,
                store_raw_payloads=False,
            )
        )
    ]
)
class AppModule(Module):
    pass


async with Application.boot(modules=[AppModule]) as app:
    # use app.container to resolve services
    ...

Configuration

Zero-config usage: Call FeedbackModule.configure() with no arguments to use defaults.

Option 1 — YAML file

# application.yaml
ai_feedback:
  enabled: true
  async_processing: true
  store_raw_payloads: false

Option 2 — Profiles + Environment Variables (recommended)

export LEX_AI_FEEDBACK__ENABLED=true
# Environment variables for each field

Option 3 — Python

from lexigram.ai.feedback.config import FeedbackConfig
from lexigram.ai.feedback import FeedbackModule

config = FeedbackConfig(
    enabled=True,
    async_processing=True,
    store_raw_payloads=False,
)
FeedbackModule.configure(config)

Config reference

Field Default Env var Description
enabled True LEX_AI_FEEDBACK__ENABLED Master on/off switch for all feedback collection
async_processing True LEX_AI_FEEDBACK__ASYNC_PROCESSING Process feedback handlers asynchronously in the background
store_raw_payloads False LEX_AI_FEEDBACK__STORE_RAW_PAYLOADS Persist raw incoming feedback payloads for auditing

Module Factory Methods

Method Description
FeedbackModule.configure(config) Configure with explicit config
FeedbackModule.stub() Minimal config for testing

Key Features

  • Four feedback types: Rating, free-text, correction (original → corrected), and ground-truth labels
  • Extensible processor pipeline: Custom processors via FeedbackProcessorRegistry
  • Storage backends: In-memory, database (DatabaseFeedbackStore), and cache (CachedFeedbackStore)
  • Middleware integration: FeedbackMiddleware and FeedbackContext for request/response capture
  • Lifecycle hooks: FeedbackSubmittedHook, FeedbackProcessedHook, FeedbackStoredHook

Security

Enforced payload size limits

Submitted feedback is validated at the submission chokepoints (FeedbackCollector._store() for the middleware/processor pipeline and the collect_* API; FeedbackService.submit_feedback() for the programmatic service). Oversized payloads are rejected with FeedbackTooLargeError (never silently truncated); boundary values (exactly at the limit) pass.

Limit Constant Applied to
10,000 characters MAX_FEEDBACK_TEXT_LENGTH TEXT feedback values and submit_feedback(comment=...)
50,000 characters (serialized JSON) MAX_CONTEXT_SIZE context and metadata dicts

Optional endpoint authorization

create_feedback_endpoint() performs no identity check by default — an endpoint mounted without an authorize callback accepts feedback from anyone who can reach it; that is an explicit, informed choice, not an enforced control. Pass an authorization callback to gate submissions:

from lexigram.ai.feedback import FeedbackCollector, FeedbackMiddleware


def authorize(ctx) -> bool:
    # ctx.context_id is the context being submitted against;
    # ctx.metadata carries what the host framework supplied (e.g. user)
    return ctx.metadata.get("user_id") is not None


middleware = FeedbackMiddleware(
    collector=FeedbackCollector(),
    authorize=authorize,
)
app.post("/feedback", middleware.create_feedback_endpoint())

Sync and async (bool | Awaitable[bool]) callables are supported. A denied submission raises FeedbackAuthorizationError before any processing.

Testing

async with Application.boot(modules=[FeedbackModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ai/feedback/module.py FeedbackModule.configure(), .stub()
src/lexigram/ai/feedback/config.py FeedbackConfig
src/lexigram/ai/feedback/services/collector.py FeedbackCollector core service
src/lexigram/ai/feedback/storage/database.py DatabaseFeedbackStore
src/lexigram/ai/feedback/storage/cache.py CachedFeedbackStore
src/lexigram/ai/feedback/processors/processor_registry.py FeedbackProcessorRegistry
src/lexigram/ai/feedback/di/provider.py FeedbackProvider boot and registration

Download files

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

Source Distribution

lexigram_ai_feedback-0.1.5001.tar.gz (48.7 kB view details)

Uploaded Source

Built Distribution

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

lexigram_ai_feedback-0.1.5001-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_feedback-0.1.5001.tar.gz.

File metadata

File hashes

Hashes for lexigram_ai_feedback-0.1.5001.tar.gz
Algorithm Hash digest
SHA256 e59d8055ca76f322d29b8b27c556ce65ed89ceb7ed833c2ee6ba3345b8f00c5e
MD5 0837221a56bfaa7d8f7d07deb546a949
BLAKE2b-256 a28626fee7465bac037f8dce8548c2b5a3b295af2bcd0bf98e14e04673cd4ab5

See more details on using hashes here.

File details

Details for the file lexigram_ai_feedback-0.1.5001-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ai_feedback-0.1.5001-py3-none-any.whl
Algorithm Hash digest
SHA256 d438bb8b37ca551ae5fd1342e3aebfd3cb65d88043299315140941fec215c435
MD5 22407b40b6e9b433fd4b2cb94058a4e0
BLAKE2b-256 8854a17b52620f9a917fc6e9ee0b2477f727a69235f3fed14b0fbf9dd4fadbe2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5003

1 file

This release

0.1.5001 This release

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

0.1.2

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page