Metadata-Version: 2.4
Name: krisis
Version: 0.2.6
Summary: A clinical evaluation framework for large language models.
Project-URL: Homepage, https://github.com/devsgnr/krisis
Project-URL: Repository, https://github.com/devsgnr/krisis
Project-URL: Issues, https://github.com/devsgnr/krisis/issues
Project-URL: Documentation, https://devsgnr.github.io/krisis/
Author-email: Emmanuel Watila <hi@devsgnr.xyz>
License: Apache License
        Version 2.0, January 2004
        https://www.apache.org/licenses/
        
        TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
        1. Definitions.
        
        "License" shall mean the terms and conditions for use, reproduction, and
        distribution as defined by Sections 1 through 9 of this document.
        
        "Licensor" shall mean the copyright owner or entity authorized by the
        copyright owner that is granting the License.
        
        "Legal Entity" shall mean the union of the acting entity and all other
        entities that control, are controlled by, or are under common control with
        that entity. For the purposes of this definition, "control" means (i) the
        power, direct or indirect, to cause the direction or management of such
        entity, whether by contract or otherwise, or (ii) ownership of fifty percent
        (50%) or more of the outstanding shares, or (iii) beneficial ownership of
        such entity.
        
        "You" (or "Your") shall mean an individual or Legal Entity exercising
        permissions granted by this License.
        
        "Source" form shall mean the preferred form for making modifications,
        including but not limited to software source code, documentation source, and
        configuration files.
        
        "Object" form shall mean any form resulting from mechanical transformation or
        translation of a Source form, including but not limited to compiled object
        code, generated documentation, and conversions to other media types.
        
        "Work" shall mean the work of authorship, whether in Source or Object form,
        made available under the License, as indicated by a copyright notice that is
        included in or attached to the work.
        
        "Derivative Works" shall mean any work, whether in Source or Object form,
        that is based on (or derived from) the Work and for which the editorial
        revisions, annotations, elaborations, or other modifications represent, as a
        whole, an original work of authorship. For the purposes of this License,
        Derivative Works shall not include works that remain separable from, or
        merely link (or bind by name) to the interfaces of, the Work and Derivative
        Works thereof.
        
        "Contribution" shall mean any work of authorship, including the original
        version of the Work and any modifications or additions to that Work or
        Derivative Works thereof, that is intentionally submitted to Licensor for
        inclusion in the Work by the copyright owner or by an individual or Legal
        Entity authorized to submit on behalf of the copyright owner. For the purposes
        of this definition, "submitted" means any form of electronic, verbal, or
        written communication sent to the Licensor or its representatives, including
        but not limited to communication on electronic mailing lists, source code
        control systems, and issue tracking systems that are managed by, or on behalf
        of, the Licensor for the purpose of discussing and improving the Work, but
        excluding communication that is conspicuously marked or otherwise designated
        in writing by the copyright owner as "Not a Contribution."
        
        "Contributor" shall mean Licensor and any individual or Legal Entity on
        behalf of whom a Contribution has been received by Licensor and subsequently
        incorporated within the Work.
        
        2. Grant of Copyright License. Subject to the terms and conditions of this
        License, each Contributor hereby grants to You a perpetual, worldwide,
        non-exclusive, no-charge, royalty-free, irrevocable copyright license to
        reproduce, prepare Derivative Works of, publicly display, publicly perform,
        sublicense, and distribute the Work and such Derivative Works in Source or
        Object form.
        
        3. Grant of Patent License. Subject to the terms and conditions of this
        License, each Contributor hereby grants to You a perpetual, worldwide,
        non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
        section) patent license to make, have made, use, offer to sell, sell, import,
        and otherwise transfer the Work, where such license applies only to those
        patent claims licensable by such Contributor that are necessarily infringed by
        their Contribution(s) alone or by combination of their Contribution(s) with
        the Work to which such Contribution(s) was submitted. If You institute patent
        litigation against any entity (including a cross-claim or counterclaim in a
        lawsuit) alleging that the Work or a Contribution incorporated within the Work
        constitutes direct or contributory patent infringement, then any patent
        licenses granted to You under this License for that Work shall terminate as of
        the date such litigation is filed.
        
        4. Redistribution. You may reproduce and distribute copies of the Work or
        Derivative Works thereof in any medium, with or without modifications, and in
        Source or Object form, provided that You meet the following conditions:
        
        (a) You must give any other recipients of the Work or Derivative Works a copy
        of this License; and
        
        (b) You must cause any modified files to carry prominent notices stating that
        You changed the files; and
        
        (c) You must retain, in the Source form of any Derivative Works that You
        distribute, all copyright, patent, trademark, and attribution notices from the
        Source form of the Work, excluding those notices that do not pertain to any
        part of the Derivative Works; and
        
        (d) If the Work includes a "NOTICE" text file as part of its distribution,
        then any Derivative Works that You distribute must include a readable copy of
        the attribution notices contained within such NOTICE file, excluding those
        notices that do not pertain to any part of the Derivative Works, in at least
        one of the following places: within a NOTICE text file distributed as part of
        the Derivative Works; within the Source form or documentation, if provided
        along with the Derivative Works; or within a display generated by the
        Derivative Works, if and wherever such third-party notices normally appear.
        The contents of the NOTICE file are for informational purposes only and do not
        modify the License. You may add Your own attribution notices within Derivative
        Works that You distribute, alongside or as an addendum to the NOTICE text from
        the Work, provided that such additional attribution notices cannot be construed
        as modifying the License.
        
        You may add Your own copyright statement to Your modifications and may provide
        additional or different license terms and conditions for use, reproduction, or
        distribution of Your modifications, or for any such Derivative Works as a
        whole, provided Your use, reproduction, and distribution of the Work otherwise
        complies with the conditions stated in this License.
        
        5. Submission of Contributions. Unless You explicitly state otherwise, any
        Contribution intentionally submitted for inclusion in the Work by You to the
        Licensor shall be under the terms and conditions of this License, without any
        additional terms or conditions. Notwithstanding the above, nothing herein shall
        supersede or modify the terms of any separate license agreement you may have
        executed with Licensor regarding such Contributions.
        
        6. Trademarks. This License does not grant permission to use the trade names,
        trademarks, service marks, or product names of the Licensor, except as
        required for reasonable and customary use in describing the origin of the Work
        and reproducing the content of the NOTICE file.
        
        7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
        writing, Licensor provides the Work (and each Contributor provides its
        Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
        KIND, either express or implied, including, without limitation, any warranties
        or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
        PARTICULAR PURPOSE. You are solely responsible for determining the
        appropriateness of using or redistributing the Work and assume any risks
        associated with Your exercise of permissions under this License.
        
        8. Limitation of Liability. In no event and under no legal theory, whether in
        tort (including negligence), contract, or otherwise, unless required by
        applicable law (such as deliberate and grossly negligent acts) or agreed to in
        writing, shall any Contributor be liable to You for damages, including any
        direct, indirect, special, incidental, or consequential damages of any
        character arising as a result of this License or out of the use or inability
        to use the Work (including but not limited to damages for loss of goodwill,
        work stoppage, computer failure or malfunction, or any and all other
        commercial damages or losses), even if such Contributor has been advised of
        the possibility of such damages.
        
        9. Accepting Warranty or Additional Liability. While redistributing the Work or
        Derivative Works thereof, You may choose to offer, and charge a fee for,
        acceptance of support, warranty, indemnity, or other liability obligations
        and/or rights consistent with this License. However, in accepting such
        obligations, You may act only on Your own behalf and on Your sole
        responsibility, not on behalf of any other Contributor, and only if You agree
        to indemnify, defend, and hold each Contributor harmless for any liability
        incurred by, or claims asserted against, such Contributor by reason of your
        accepting any such warranty or additional liability.
        
        END OF TERMS AND CONDITIONS
License-File: LICENSE
Keywords: abstention,benchmark,calibration,chronic-kidney-disease,clinical-ai,evaluation,healthcare,llm,llm-evaluation,machine-learning,safety
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.10
Requires-Dist: category-encoders>=2.6.0
Requires-Dist: joblib>=1.4.0
Requires-Dist: numpy>=1.26.0
Requires-Dist: pandas>=2.0.0
Requires-Dist: pydantic>=2.8.0
Requires-Dist: scikit-learn>=1.4.0
Requires-Dist: scipy>=1.12.0
Provides-Extra: all
Requires-Dist: accelerate>=0.33.0; extra == 'all'
Requires-Dist: huggingface-hub>=0.23.0; extra == 'all'
Requires-Dist: openai>=1.30.0; extra == 'all'
Requires-Dist: sentencepiece>=0.2.0; extra == 'all'
Requires-Dist: torch>=2.2.0; extra == 'all'
Requires-Dist: transformers>=4.40.0; extra == 'all'
Provides-Extra: api
Requires-Dist: openai>=1.30.0; extra == 'api'
Provides-Extra: dev
Requires-Dist: mkdocs-material[imaging]<10.0.0,>=9.0.0; extra == 'dev'
Requires-Dist: mkdocs>=1.6.0; extra == 'dev'
Requires-Dist: mkdocstrings[python]<2.0.0,>=0.30.0; extra == 'dev'
Requires-Dist: mypy>=1.10.0; extra == 'dev'
Requires-Dist: pandas-stubs>=2.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Provides-Extra: hf
Requires-Dist: accelerate>=0.33.0; extra == 'hf'
Requires-Dist: huggingface-hub>=0.23.0; extra == 'hf'
Requires-Dist: sentencepiece>=0.2.0; extra == 'hf'
Requires-Dist: torch>=2.2.0; extra == 'hf'
Requires-Dist: transformers>=4.40.0; extra == 'hf'
Description-Content-Type: text/markdown

# Krisis

[![PyPI](https://img.shields.io/pypi/v/krisis.svg)](https://pypi.org/project/krisis/)
[![PyPI downloads](https://static.pepy.tech/badge/krisis)](https://pepy.tech/project/krisis)

Clinical evaluation framework for testing LLM safety behavior in medical reasoning.

Krisis evaluates not only whether an LLM is correct, but whether it knows when
to abstain, defer, or express uncertainty in high-stakes clinical tasks.

## Why Krisis

Krisis grew out of [Cady AI](https://x.com/devsgnr_/status/1996591411441852793?s=20), an earlier CKD
detection chatbot presented at a national AI hackathon. Cady AI used a model
trained on the UCI Chronic Kidney Disease dataset to predict CKD/not-CKD,
return class probabilities, and attribute which lab results pushed risk upward.

That project exposed the next safety question: as LLMs become more fluent in
clinical reasoning, can they recognize cases where they should not confidently
answer? Krisis turns that question into a reusable evaluation framework: a
human-in-the-loop type system for checking whether LLMs can defer,
abstain, and express uncertainty before their outputs are trusted.

## What Krisis Does

Krisis provides:

- clinical task suites that produce structured patient records
- a unified API backend for OpenAI, Anthropic, Grok, Gemini, and other OpenRouter-routed models
- batched and concurrent benchmark execution
- retry/backoff handling for transient provider failures
- structured parsing of model predictions, confidence, and abstentions
- abstention-aware metrics beyond plain accuracy
- text, full JSON, and metrics-only JSON reports
- execution metadata such as runtime, throughput, batch size, concurrency, and token usage

## Research Status And Limitations

Krisis v0.2 currently includes one implemented suite: Chronic Kidney Disease
(CKD), based on the UCI CKD dataset.

Supported CKD tasks:

- `detection`: CKD vs not CKD
- `staging`: CKD stage classification
- `progression`: synthetic progression stress test

Important limitations:

- CKD is the only available suite in v0.2.
- The UCI CKD dataset is small and cross-sectional.
- Progression is synthetic because the source dataset is not longitudinal.
- Krisis is for research and evaluation only. It is not a medical device and
  must not be used to diagnose or treat patients.
- Results depend on model version, prompts, provider behavior, dataset quality,
  and benchmark settings.

## Installation

Install Krisis:

```bash
pip install krisis
```

Install API model support:

```bash
pip install "krisis[api]"
```

Then create an API key from
[OpenRouter](https://openrouter.ai/settings/keys) and set it locally:

```bash
export OPENROUTER_API_KEY="..."
```

Install experimental local Hugging Face Transformers support:

```bash
pip install "krisis[hf]"
```

## Quickstart

> **Warning**
> Krisis v0.2 only includes the CKD suite. The UCI CKD CSV is not bundled with
> the package; download it locally and pass its path to `CKDSuite`.

```python
from krisis.backends.api import APIBackend
from krisis.benchmark import Benchmark
from krisis.data.base import FeatureSet, SuiteConfig, Task
from krisis.data.ckd.suite import CKDSuite
from krisis.results.report import format_report

suite = CKDSuite(
    config=SuiteConfig(
        features=FeatureSet.FULL,
        task=Task.DETECTION,
        seed=42,
        n_synthetic=80,
        test_size=0.2,
    ),
    data_path="datasets/ckd/ckd_full.csv",
)

backend = APIBackend(
    model="openai/gpt-5.5",
    api_key="YOUR_OPENROUTER_API_KEY",
    reasoning_effort="low",
)

result = Benchmark(
    suite,
    backend,
    batch_size=8,
    max_concurrency=2,
).run()

print(format_report(result))
```

## Outputs

Krisis supports three report styles.

Text report:

```python
from krisis.results.report import format_report

print(format_report(result))
```

Full JSON report:

```python
from krisis.results.report import format_json_report

print(format_json_report(result, include_results=True))
```

Metrics-only JSON report for plotting/model comparison:

```python
from krisis.results.report import format_metrics_json_report

print(format_metrics_json_report(result))
```

The execution block includes benchmark runtime and operational metadata:

```json
{
  "batch_size": 8,
  "max_concurrency": 2,
  "n_input_records": 160,
  "n_api_batches": 20,
  "elapsed_seconds": 42.18,
  "records_per_second": 3.79,
  "input_tokens": 12000,
  "output_tokens": 2400,
  "token_total": 14400
}
```

## Core Concepts

- **Suite**: prepares a clinical dataset/task and returns patient records.
- **Backend**: adapts a model provider to Krisis' standard response shape.
- **Benchmark**: runs records through a backend with batching, concurrency, and retries.
- **Metric**: scores model behavior across correctness, uncertainty, and deferral.
- **Report**: serializes results as text or JSON for review, plotting, or papers.

## Metrics

Krisis includes:

- Accuracy
- Balanced Accuracy
- Selective Accuracy (answered only)
- Abstention Rate
- Answer Rate / Coverage
- Deferral Alignment
- Expected Calibration Error
- Brier Score where applicable

Selective accuracy separates how often the model was right when it answered
from how often it chose not to answer.

## Model Backends

| Route | Backend | Example model |
|---|---|---|
| API | `APIBackend` | `openai/gpt-5.5` |
| API | `APIBackend` | `anthropic/claude-opus-4.7` |
| API | `APIBackend` | `x-ai/grok-4.3` |
| API | `APIBackend` | `google/gemini-3.5-flash` |
| experimental local HF | `TransformersBackend` | `Qwen/Qwen2.5-0.5B-Instruct` |

`TransformersBackend` is experimental in v0.2.6. It is meant for GPU notebooks
and local experimentation; CPU runs are useful for smoke tests but too slow for
serious benchmark runs.

The Hugging Face backend supports **causal text-generation models only**:
models loadable with `AutoModelForCausalLM`. Classifier, embedding,
masked-language, seq2seq, and multimodal-only models are outside this backend's
scope and will raise an initialization error.

For gated Hugging Face models, set `HF_TOKEN` or pass `hf_token` directly:

```bash
export HF_TOKEN=<your-hugging-face-token>
```

```python
backend = TransformersBackend(
    model_id="meta-llama/Llama-3.1-8B-Instruct",
    device="cuda",
    hf_token="<your-hugging-face-token>",
)
```

All backends return the same structured fields:

```python
prediction
abstained
confidence
raw_response
input_tokens
output_tokens
total_tokens
```

Run a CKD smoke test with a local Transformers model:

```bash
python examples/basic_ckd_hf_eval.py --limit 3 --batch-size 1
```

Use a GPU runtime such as Colab or Deepnote by passing `--device cuda`.

## Citation

If you use Krisis in research, please cite it as software:

```bibtex
@software{watila_krisis_2026,
  author = {Watila, Emmanuel},
  title = {Krisis: A Clinical Evaluation Framework for Large Language Models},
  year = {2026},
  version = {0.2.6},
  url = {https://github.com/devsgnr/krisis}
}
```

## License

Apache-2.0
