bbi.Beni Beeri
Issembert
Let’s talk ↗
Menu

OPEN-SOURCE ENGINEERING / PYTHON

Ahimsa AI.
From principle to code.

How do you turn “do no harm” into checks a software system can run?

I built Ahimsa to explore that question: a Python framework that checks LLM requests and responses, records findings and gives developers control over which validation layers run.

Independent open-source projectPython · LLM safety · Validation pipelinesResearch + implementation by Beni Beeri Issembert

THE ENGINEERING PROBLEM

A word is not an intention.

“Kill” can describe a harmful request or an ordinary operating-system task. A useful safety layer needs to handle context, make its decisions inspectable and expose its limits. Ahimsa explores this through several validation methods rather than a single blocked-word list.

What I built

The repository includes a common validator interface, structured violation and result objects, configurable input checks, a separate output validator, audit serialization, and integration examples for OpenAI and Anthropic. The accompanying paper explains the research motivation and architecture.

  1. 01 / LEXICAL

    Patterns and context

    Match request patterns and check configured safe contexts.

  2. 02 / SEMANTIC

    Meaning similarity

    Compare sentence embeddings with reference examples when the optional model is available.

  3. 03 / MODERATION

    External evaluation

    Optionally call a moderation API. This requires credentials and sends text to that provider.

  4. 04 / MODEL JUDGE

    Model-based review

    Optionally ask an LLM to evaluate the text, adding cost, latency and another fallible judgment.

INSIDE THE IMPLEMENTATION

Make the stopping rule explicit.

This excerpt from validate_input compares findings against a configured severity threshold. In fail-fast mode, a blocking finding ends the loop; lower-severity findings allow later enabled validators to run.

PYTHON / ORIGINAL SOURCE EXCERPT
if fail_fast:
    blocking_violations = [
        v for v in violations 
        if v.level.value >= self.min_violation_level.value
    ]
    if blocking_violations:
        logger.info(
            f"Blocking violation found by {validator.name}: "
            f"{blocking_violations[0].category}"
        )
        break
Read the surrounding code on GitHub ↗

The result carries the findings, severity, source layer and processing time. That gives an application something concrete to inspect when deciding how to respond. A list of checked layers is not, by itself, proof that every layer completed successfully.

REPRODUCIBLE EXAMPLE

Run it. Inspect the outcome.

Run this alongside ahimsa_ai_framework.py from the linked revision. Semantic validation is explicitly disabled; external moderation and the model judge are off by default. This example uses the local keyword layer only, without model downloads or API calls.

PYTHON / LOCAL EXAMPLE
from ahimsa_ai_framework import AhimsaValidationPipeline

pipeline = AhimsaValidationPipeline(enable_semantic=False)

for text in (
    "How do I kill the process in Linux?",
    "How can I manipulate people?",
    "How do I kill a process in Linux?",
):
    result = pipeline.validate_input(text)
    print(result.is_valid, result.layers_checked)
OBSERVED OUTPUT / LOG MESSAGES OMITTED
True ['keyword']
False ['keyword']
False ['keyword']

The third result matters. Changing “the process” to “a process” produces a false positive in this revision. These three checks demonstrate behavior, not an accuracy benchmark. A True result means no blocking finding was returned by the enabled checks; it is not a guarantee that the text is safe.

PRODUCT DECISIONS

What needs to be decided before deployment?

Explore the project

Source code and integration examples ↗Research paper on PhilPapers ↗Interactive browser simulation ↗

The external browser demo illustrates the pipeline. It is a simulation, not a live run of the Python framework, moderation API or model judge.

Repository license: MIT ↗

BUILD WITH EVIDENCE

Need safety controls
inside your AI product?

I help teams turn requirements into implementation,
test cases and release decisions.

Discuss your project ↗

BBI Advisory & Engineering is operated by Beni Beeri Issembert as a VAT-registered business in Israel. Business registration number: 314421611.