Skip to main content

A Django library for AI-powered data validation and cleaning.

Project description

Django AI Validator

PyPI version License: MIT codecov Documentation

Documentation: https://mazafard.github.io/django-ai-validator/

A Django library for AI-powered data validation and cleaning.

Features

  • Semantic Validation: Validate data based on meaning using LLMs.
  • Automated Cleaning: Automatically clean and normalize data.
  • Admin Integration: Bulk actions and status indicators in Django Admin.
  • Asynchronous Support: Offload LLM calls to Celery tasks.
  • Multiple Providers: Support for OpenAI, Anthropic, Gemini, and Ollama.

Installation

pip install django-ai-validator

Configuration

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_ai_validator',
]

Set your API key:

# Defaults to OpenAIClient
AI_CLEANER_LLM_CLIENT = 'django_ai_validator.llm.client.OpenAIClient'
OPENAI_API_KEY = "your-api-key"

Usage

Semantic Validation

from django.db import models
from django_ai_validator.validators import AISemanticValidator

class Product(models.Model):
    description = models.TextField(
        validators=[
            AISemanticValidator(
                prompt_template="Ensure the description is marketing-friendly and contains no offensive language."
            )
        ]
    )

Automatic Cleaning

from django_ai_validator.fields import AICleanedField

class UserProfile(models.Model):
    bio = AICleanedField(
        cleaning_prompt="Fix grammar and remove personal contact info."
    )

Admin Integration

from django.contrib import admin
from django_ai_validator.admin import AIAdminMixin
from .models import MyModel

@admin.register(MyModel)
class MyModelAdmin(AIAdminMixin, admin.ModelAdmin):
    list_display = ['content', 'is_dirty']
    actions = ['run_ai_cleanup_on_selected']

Manual Validation

To check if user input contains bad words:

from django_ai_validator.validators import AISemanticValidator

class Comment(models.Model):
    text = models.TextField(
        validators=[
            AISemanticValidator(
                prompt_template="Check if this text contains bad words. Return VALID if not."
            )
        ]
    )

Asynchronous Cleaning

To automatically remove personal information:

from django_ai_validator.fields import AICleanedField

class Feedback(models.Model):
    message = AICleanedField(
        cleaning_prompt="Remove PII.",
    )

Star History

Star History Chart

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

django_ai_validator-0.1.5.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

django_ai_validator-0.1.5-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file django_ai_validator-0.1.5.tar.gz.

File metadata

  • Download URL: django_ai_validator-0.1.5.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_ai_validator-0.1.5.tar.gz
Algorithm Hash digest
SHA256 e8b4b3848c720d8dcb2a9d863bbadedac75709c87f8fffd75c86dba2388d9192
MD5 e3eecd4b2aaa2da1362a6a637f5393c7
BLAKE2b-256 09bd7611ee552159b9185b1f8487c2a19cf2eaf6c23ec9026f453b9ac94174da

See more details on using hashes here.

File details

Details for the file django_ai_validator-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ai_validator-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 71138068db893684603e046b5d641bf3a7376edd104796e5be6bb783ff2b23da
MD5 7b359f3491b1ec2661afab3b062c8a9d
BLAKE2b-256 08171979ae207083be141e89159f7e8ab5dd6bb7006857774f01c3a49a33cf71

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