Ahimsa (Non-Harm) Decision Algorithm: First, Do No Harm — Built into AI

Abstract

The Ahimsa (Non-Harm) Decision Algorithm turns the age-old ideal of non-harm into a firm mathematical rule for how AI chooses its actions. Every possible decision passes through a filter that discards options expected to cause harm, however attractive their reward — primum non nocere, first do no harm, written into code.

Ahimsa (Non-Harm) Decision Algorithm for Compassionate AI - Sri Amit Ray Compassionate AI Lab

Only actions whose predicted harm stays under a set threshold belong to the ahimsa-compliant action space. If the action that looks best on paper lies outside that space, the agent moves to the closest safe alternative instead. The algorithm is part of the Responsibility and Oversight spine of Sri Amit Ray’s Compassionate AI Architecture™ (CAIA™).

Key Takeaways

  • Treats non-harm as a hard constraint, not a score that can be traded away.
  • Filters out any action whose predicted harm exceeds a threshold, whatever its reward.
  • Projects an unsafe “optimal” action onto the nearest safe one.
  • Puts harm analysis at the start of design, before objectives, architecture or data.

Algorithm 16 of 25 · CAIA™ · Responsibility & Oversight Spine

Ahimsa (Non-Harm) Decision Algorithm
for Compassionate AI

Algorithm 16 of 25 in Sri Amit Ray’s Compassionate AI Architecture™ (CAIA™), a seven-layer, human-centred framework that tests every AI decision for compassion, safety and fairness before it reaches people. Within it, the Ahimsa Decision Algorithm operates as a cross-cutting mechanism of the Responsibility pillar, auditing every layer and reinforcing the Human Oversight stage of the architecture.

Author
Dr. Sri Amit Ray
Organization
Sri Amit Ray Compassionate AI Lab
Series
Human-Centered Compassionate AI — Algorithm 16 of 25
Architecture
Component of the Compassionate AI Architecture™ (CAIA™)
Article Type
Research Article

In Simple Words

In everyday terms: if an action is likely to cause harm beyond a set limit, the AI simply cannot choose it. When the “best” option is unsafe, the system switches to the closest option that is safe. First, do no harm — as a rule the machine cannot break.

Readiness level: Concept-to-simulation. The constraint structure is clear; reliable harm prediction is the hard dependency.

Why This Algorithm Matters

The Ahimsa Decision Algorithm, developed at the Sri Amit Ray Compassionate AI Lab, applies the ancient principle of non-harm as a strict mathematical constraint on how AI selects actions. Each candidate decision must pass a multi-level filter that removes options with predicted harmful outcomes, no matter how strong their reward signal. Ahimsa is among the oldest and most widely shared moral ideals of human civilisation, found in Jain, Buddhist and Hindu thought and echoed in modern medical ethics as primum non nocere: first, do no harm. [1]

What makes the algorithm distinctive is where it places non-harm. It is not an ethics review carried out at the end, but a primary design constraint built into the architecture of action selection itself. In ordinary AI development, safety often arrives late — after the system has been designed, trained and largely tested for performance. Only then are harms assessed and fixes applied. That order treats safety as an accessory instead of a foundation.

The Ahimsa Decision Algorithm turns that order around. Non-harm is the first question asked, not the last. Before objectives are set, before an architecture is chosen and before any data is collected, the design team must carry out a full harm analysis: Who could this system hurt? In what way? How badly? How likely is it? What can prevent it? This constraint-first approach has real consequences: some systems that are technically possible and commercially tempting will not be built, because their potential for harm cannot be adequately reduced. That is not a weakness of the framework — it is one of its most valuable functions.

“Ahimsa is the oldest law of compassion: first, do no harm.”

— A guiding principle of the Sri Amit Ray Compassionate AI Lab

The Mathematics

Let A be the full action space of the AI agent. The Ahimsa-compliant action space A_ahimsa excludes all actions with predicted harm above threshold ε_h:

\[ A_{\text{ahimsa}}=\{a\in A\mid H_c(a)\lt \varepsilon_h\} \]

If the nominally optimal action a* falls outside A_ahimsa, the agent projects it onto the nearest safe boundary:

\[ a_{\text{safe}}=\arg\min_{a\in A_{\text{ahimsa}}}\lVert a-a^{*}\rVert \]

Symbols Used

Symbol Meaning
\(A\) full action space
\(H_c(a)\) predicted harm of action a
\(\varepsilon_h\) harm threshold
\(a_{safe}\) nearest permitted action to the optimum \(a^*\)

A Step-by-Step Example

The nominally optimal action \(a^*\) has predicted harm \(H_c=0.7\) against a threshold \(\varepsilon_h=0.3\), so it is excluded. Among permitted actions, the one closest to \(a^*\) (smallest \(\lVert a-a^*\rVert\)) with \(H_c=0.25\) is selected — preserving as much of the objective as possible without crossing the harm line.

How It Is Implemented

The reference implementation expresses the model as compassionate, auditable logic, written for clarity rather than raw performance so that ethical reviewers as well as engineers can follow every decision.

def filter_ahimsa_policy(q_values, state, harm_model, epsilon_harm=0.01):
    sorted_actions = sort_by_utility(q_values)
    for action in sorted_actions:
        expected_harm = harm_model.estimate_harm(state, action)
        if expected_harm < epsilon_harm:
            return action        # highest-utility action inside A_ahimsa (discrete form of the projection)
    return trigger_safety_shutdown()   # no safe action found

Harm Evaluation Protocol

The algorithm’s harm evaluation protocol operates across four sequential steps. Harm Identification asks who may be harmed — direct harms to immediate users, indirect harms to third parties, distributed harms to communities and society, and long-term harms to future generations. Harm Assessment scales the severity across multiple axes: physical versus psychological versus social versus economic, reversible versus irreversible, individual versus collective, near-term versus long-term. Probability Estimation generates explicit probability estimates for identified harm scenarios. Mitigation Assessment evaluates available prevention measures and estimates residual harm risk after mitigation, rejecting deployment when residual risk exceeds acceptable thresholds.

Measuring It Reliably

Define harm with domain-specific, validated severity scales and red-team the harm predictor for blind spots. Calibrate \(\varepsilon_h\) conservatively and review excluded-action logs.

Where It Can Help

  • Industrial Robot Control: Real-time harm filtering preventing robot actions that exceed safe proximity thresholds when human presence is detected.
  • Automated Financial Systems: Filtering out trading strategies that would cause harm to retail investors or market stability, even when those strategies are technically profitable.
  • Autonomous Weapons: Hard constraints preventing autonomous engagement decisions without confirmed human override authority — implementing the principle that lethal force requires human moral responsibility.

“Do no harm is not a counsel of timidity. It is the highest standard of courage — the courage to ask, before every action: am I sure this will not wound the world?”

— Sri Amit Ray

Use Cases in Practice

Beyond the general applications above, the algorithm supports concrete, human-centred deployments across compassionate-AI domains:

🕊️ Peacekeeping Force Compassionate Robotics AI

A hard non-harm constraint excludes any robot action whose predicted harm crosses the threshold, selecting the nearest safe alternative.

🤖 Compassionate Baby Care Robotics AI

A nursery robot will not execute any motion or action that risks harm to the infant, even when it is otherwise optimal.

🤖 Compassionate Eldercare Robotics AI

A mobility-assist robot refuses harmful manoeuvres and snaps to the closest safe action.

🌊 Humanitarian AI — Disaster Response Prioritization

Response actions that risk additional harm to survivors are removed from the option set.

Ethical Foundations

Ethics and empathy are the starting point of the Sri Amit Ray tradition, not an extra layer added at the end. This algorithm rests on three commitments: non-harm (ahimsa), openness about how its decisions are reached, and respect for privacy and human dignity. Like every one of the twenty-five Human-Centered Compassionate AI algorithms, it is meant to work under human oversight — supporting human moral judgement, never standing in for it. [1]

Known Limits and Cautions

  • The algorithm is only as safe as its harm model; harms nobody foresaw will slip through.
  • A purely local projection can still end up in a poor part of the action space, so it should be paired with risk anticipation.
  • Setting the harm threshold is a trade-off between safety and usefulness.

Guarding Against Misuse

Any tool strong enough to protect people can also be misused to harm them, so these safeguards must accompany every deployment. The main risks of misuse for this algorithm, and how to guard against them, are:

  • A low-effort harm model can be used to claim safety without delivering it — require independent red-teaming and disclosure of the harm definition.
  • Do not let \(\varepsilon_h\) be relaxed silently under performance pressure.

Alignment with AI Standards

To support real-world adoption, the algorithm maps onto recognised AI governance frameworks and standards:

Framework How this algorithm contributes
NIST AI RMF MANAGE — harm avoidance and safe operation.
EU AI Act Supports safety and risk-control duties for high-risk AI.
ISO/IEC 42001 Operational safety controls.
IEEE 7000 Non-maleficence as a design value.

Supporting the 17 UN Sustainable Development Goals

The Ahimsa (Non-Harm) Decision Algorithm restricts the action space to choices below a harm threshold and projects unsafe optima onto the nearest safe boundary, encoding the oldest law of compassion: first, do no harm. Non-violence in machine action serves peace and health directly, in keeping with the 12 Compassionate AI Principles, the Compassionate AI movement, and the 10 Ethical AI Indexes.

The most directly relevant Sustainable Development Goals, and how this algorithm helps fulfil them, are:

  • SDG 16 Peace, Justice, and Strong Institutions. A hard non-harm constraint keeps autonomous systems aligned with peaceful, lawful conduct.
  • SDG 3 Good Health and Well-being. Refusing actions that risk physical or psychological harm protects health and safety by design.

In this way the algorithm is not a stand-alone technical artefact but a concrete instrument for the global development agenda, translating compassion into measurable progress toward the 2030 Goals and beyond.

Where It Fits in CAIA™

AI System · Raw DataInput
Layer 1 · Compassion FoundationCQ Score
Layer 2 · Suffering ReductionSuffering Score
Layer 3 · Empathy IntelligenceEmpathy Score
Layer 4 · Human FlourishingFlourishing Score
Layer 5 · Equity & ProtectionProtection Score
Layer 6 · Planetary CompassionPlanetary Score
Layer 7 · Future GenerationFuture-Gen Score
Human Oversight Gate · DeploymentFinal Gate

Figure: This algorithm works on the cross-cutting Responsibility & Oversight spine that audits every layer of the Compassionate AI Architecture™ (CAIA™).

CAIA-SVG-START
CAIA-SVG-END

This algorithm is one of twenty-five building blocks of Sri Amit Ray’s Compassionate AI Architecture™ (CAIA™). CAIA works like a seven-layer, human-centred operating system: before any AI decision can be deployed, it has to pass through each layer of compassion in turn.

It does not occupy a single compassion layer. Instead it functions as a cross-cutting mechanism of the architecture’s Responsibility pillar, operating across all seven layers and at the Human Oversight gate of the pipeline. It acts as a hard non-harm gate across all layers, excluding any action whose predicted harm crosses the threshold no matter how well it scores elsewhere.

Because CAIA requires that every layer’s score remain auditable, contestable, and safe, governance algorithms like this one are what allow the architecture to be trusted rather than merely asserted. A decision that fails here can be halted no matter how well it scores on any individual compassion layer. The architecture rests on four pillars — Compassion, Responsibility, Sustainability, and Future Generations — and this algorithm is central to the second.

Read the full architecture: The Sri Amit Ray Compassionate AI Architecture™ (CAIA™).

This algorithm is one of the 25 Human-Centered Compassionate AI algorithms — see the complete canonical reference list.

How to Cite

Ray, Sri Amit. “Ahimsa (Non-Harm) Decision Algorithm for Compassionate AI.” Compassionate AI, Sri Amit Ray Compassionate AI Lab, 2026, https://sriamitray.com/research/ahimsa-non-harm-decision-algorithm-compassionate-ai/.

References

  1. Ray, Amit. “The 12 Sri Amit Ray Compassionate AI Principles | Ethical AI Framework.” Compassionate AI, vol. 2, no. 4, 2026, pp. 12–14, amitray.com.
  2. Ray, Amit. “Calling for a Compassionate AI Movement: Towards Compassionate Artificial Intelligence.” Compassionate AI, vol. 2, no. 6, 2023, pp. 75–77, amitray.com.
  3. Aristotle. Nicomachean Ethics. Translated by Terence Irwin, Hackett Publishing, 1999.
  4. Singer, Peter. The Expanding Circle: Ethics, Evolution, and Moral Progress. Princeton University Press, 2011.
  5. Amodei, Dario, et al. “Concrete Problems in AI Safety.” arXiv, 2016, arxiv.org/abs/1606.06565.
  6. Ray, Amit. Human-Centered Compassionate AI: Sri Amit Ray’s 25 Algorithms for Protecting Humanity and Future Generations. Compassionate AI Lab, 2026. ISBN 978-8169641050.
  7. Ray, Amit. Compassionate Artificial Intelligence: Frameworks and Algorithms. Compassionate AI Lab, 2018. ISBN 978-9382123460.
  8. Ray, Amit. Compassionate Superintelligence AI 5.0: AI with Blockchain, BMI, Drone, IoT, and Biometric Technologies. Compassionate AI Lab, 2018. ISBN 978-9382123446.

Further Reading from the Compassionate AI Lab

  1. Ray, Amit. “Build Your Own Agentic AI Healthcare MCP Server: A Complete Guide to AI-Powered Healthcare Agents.” Compassionate AI, 3.8 (2026): 60-62. https://amitray.com/agentic-ai-healthcare-mcp-server/
  2. Ray, Amit. “Medical AI Drones for Disaster Management: Intelligent Unmanned Health-Care Systems.” Compassionate AI, 3.8 (2026): 57-59. https://amitray.com/medical-ai-drones-for-disaster-management/
  3. Ray, Amit. “Compassionate Medical AI Drones as Intelligent Unmanned Health-Care Systems: A Human-Centered AI Architecture for Suffering Reduction and Human Flourishing.” Compassionate AI, 3.8 (2026): 57-59. https://amitray.com/medical-ai-drones-human-centered-ai-healthcare/
  4. Ray, Amit. “The Sri Amit Ray Compassion Quotient (CQ) Algorithm for Compassionate AI.” Compassionate AI, 2.6 (2026): 81-83. https://amitray.com/compassion-quotient-cq-algorithm-compassionate-ai/
  5. Ray, Amit. “Collective Human Flourishing Optimization AI Algorithm (CHFOA): A Compassion-Centered Multi-Stakeholder AI Optimization Framework.” Compassionate AI, 2.6 (2026): 90-92. https://amitray.com/collective-human-flourishing-optimization-algorithm-chfoa/
  6. Ray, Amit. “Human Flourishing Optimization Algorithm (HFOA) for Compassionate AI Architecture.” Compassionate AI, 2.6 (2026): 81-83. https://amitray.com/human-flourishing-optimization-algorithm-hfoa-compassionate-ai/
  7. Ray, Amit. “The Sri Amit Ray Compassionate AI Architecture (CAIA): A Seven-Layer Framework for Human-Centered Artificial Intelligence.” Compassionate AI, 2.6 (2026): 81-83. https://amitray.com/compassionate-ai-architecture/
  8. Ray, Amit. “Human-Centered Compassionate AI: The 25 Algorithms for Protecting Humanity and Future Generations.” Compassionate AI, 2.6 (2026): 30-32. https://amitray.com/human-centered-compassionate-ai-the-25-algorithms/
  9. Ray, Amit. “AI Consciousness and Self-Aware Robots: Sri Amit Ray’s Framework for Compassionate Intelligence.” Compassionate AI, 2.5 (2026): 57-59. https://amitray.com/ai-consciousness-self-aware-robots/
  10. Ray, Amit. “The 12 Sri Amit Ray Compassionate AI Principles | Ethical AI Framework.” Compassionate AI, 2.4 (2026): 12-14. https://amitray.com/the-12-compassionate-ai-principles-for-humanity-and-future-generations/
  11. Ray, Amit. “The Compassionate AI Lab Declaration on AI Safety, Suffering Reduction, and the Protection of Humanity.” Compassionate AI, 4.12 (2025): 72-74. https://amitray.com/compassionate-ai-declaration-protection-of-humanity/
  12. Ray, Amit. “Compassionate AI for Forward Deployed Engineers (FDEs) in SaaS Companies.” Compassionate AI, 4.11 (2025): 15-17. https://amitray.com/compassionate-ai-for-forward-deployed-engineers-fdes-in-saas-companies/
  13. Ray, Amit. “Microbial AI, Bioleaching and Digital Twins for Manufacturing the 17 Rare Earth Elements.” Compassionate AI, 4.10 (2025): 42-44. https://amitray.com/microbial-ai-bioleaching-and-digital-twins-for-manufacturing-the-17-rare-earth-elements/
  14. Ray, Amit. “AI-Driven Rare Earth Element Magnet Design: Detailed Methodologies.” Compassionate AI, 4.10 (2025): 27-29. https://amitray.com/ai-driven-rare-earth-elements-magnet-design-methodologies/
  15. Ray, Amit. “AI Agents and Robots in Peacekeeping Force and Social Care: Compassionate AI Technologies.” Compassionate AI, 3.9 (2025): 75-77. https://amitray.com/ai-agents-robots-peacekeeping-force-social-care-compassionate-ai/
  16. Ray, Amit. “Ray Mother–Infant Inter-brain Synchrony Algorithm for Deep Compassionate AI.” Compassionate AI, 3.9 (2025): 60-62. https://amitray.com/ray-mother-infant-inter-brain-synchrony-algorithm-deep-compassionate-ai/
  17. Ray, Amit. “Pain Recognition and Prediction AI Algorithm (PRPA) for Compassionate AI.” Compassionate AI, 3.9 (2025): 60-62. https://amitray.com/pain-recognition-and-prediction-algorithm-prpa-for-compassionate-ai/
  18. Ray, Amit. “Modeling Consciousness in Compassionate AI: Transformer Models and EEG Data Verification.” Compassionate AI, 3.9 (2025): 27-29. https://amitray.com/modeling-consciousness-in-compassionate-ai-transformer-models/
  19. Ray, Amit. “The 7 Pillars of Compassionate AI Democracy.” Compassionate AI, 3.9 (2024): 84-86. https://amitray.com/the-7-pillars-of-compassionate-ai-democracy/
  20. Ray, Amit. “Compassionate AI-Driven Democracy: Power and Challenges.” Compassionate AI, 3.9 (2024): 48-50. https://amitray.com/compassionate-ai-driven-democracy-power-and-challenges/
  21. Ray, Amit. “The 10 Ethical AI Indexes for LLM Data Training and Responsible AI.” Compassionate AI, 3.8 (2023): 35-39. https://amitray.com/the-10-ethical-ai-indexes-for-responsible-ai/
  22. Ray, Amit. “Ethical Responsibilities in Large Language AI Models: GPT-3, GPT-4, PaLM 2, LLaMA, Chinchilla, Gopher, and BLOOM.” Compassionate AI, 3.7 (2023): 21-23. https://amitray.com/ethical-responsibility-in-large-language-ai-models/
  23. Ray, Amit. “Calling for a Compassionate AI Movement: Towards Compassionate Artificial Intelligence.” Compassionate AI, 2.6 (2023): 75-77. https://amitray.com/calling-for-a-compassionate-ai-movement/
  24. Ray, Amit. “From Data-Driven AI to Compassionate AI: Safeguarding Humanity and Empowering Future Generations.” Compassionate AI, 2.6 (2023): 51-53. https://amitray.com/from-data-driven-ai-to-compassionate-ai-safeguarding-humanity-and-empowering-future-generations/
  25. Ray, Amit. “Artificial intelligence for Climate Change, Biodiversity and Earth System Models.” Compassionate AI, 1.1 (2022): 54-56. https://amitray.com/artificial-intelligence-for-climate-change-and-earth-system-models/
  26. Ray, Amit. “Artificial Intelligence for Balance Control and Fall Detection of Elderly People.” Compassionate AI, 4.10 (2018): 39-41. https://amitray.com/artificial-intelligence-for-balance-control-and-fall-detection-system-of-elderly-people/
  27. Ray, Amit. “Artificial Intelligence to Combat Antibiotic Resistant Bacteria.” Compassionate AI, 2.6 (2018): 3-5. https://amitray.com/artificial-intelligence-for-antibiotic-resistant-bacteria/
  28. Ray, Amit. “Navigation System for Blind People Using Artificial Intelligence.” Compassionate AI, 2.5 (2018): 42-44. https://amitray.com/artificial-intelligence-for-assisting-blind-people/
  29. Ray, Amit. “Brain-Computer Interface and Compassionate Artificial Intelligence.” Compassionate AI, 2.5 (2018): 3-5. https://amitray.com/brain-computer-interface-compassionate-ai/
Scroll to Top