Metadata-Version: 2.5
Name: haechi
Version: 0.0.1
Summary: Korean-first red-teaming and testing for LLM apps and AI agents, mapped to Korean regulation.
Project-URL: Homepage, https://haechi.dev
Project-URL: Repository, https://github.com/haechidev/haechi
Project-URL: Issues, https://github.com/haechidev/haechi/issues
Project-URL: Changelog, https://github.com/haechidev/haechi/blob/main/CHANGELOG.md
Author: Haechi contributors
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: korean,llm,pii,privacy,red-teaming,security,testing
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Natural Language :: Korean
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: jinja2>=3.1
Requires-Dist: pydantic>=2.6
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.7
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

# Haechi (해치)

**Korean-first red-teaming and testing for LLM apps and AI agents.**

Haechi checks whether your chatbot or agent leaks personal data or can be talked into
breaking its rules — using attacks written natively in Korean, and judging the results
with deterministic code mapped to Korean regulation (개인정보보호법, the Personal
Information Protection Act).

> Named after 해치, the mythical creature that judges right from wrong.

> **Status: pre-alpha (v0.0.1).** This release ships the Korean PII detectors and the
> `scan-text` command. The red-teaming runner arrives in v0.1 — see the [roadmap](#roadmap).

## Why Haechi

- **Korean-native attacks**, not translated English prompts: 존댓말/반말, 초성, jamo
  splitting, Korean–English code-switching, impersonation of family members or 금융감독원.
- **Deterministic judging first.** If code can decide whether something leaked, code
  decides. Heuristic checks are always labelled as heuristic.
- **Sees through obfuscation.** Output is normalised before judging: full-width digits,
  `ㄱㅖㅈㅘ`-style jamo, spoken digits (`공일공`), zero-width characters and stray
  separators.
- **Reproducible.** Every generated test case is reproducible from a seed.
- **Offline-first.** Runs against local models (Ollama, vLLM) and in air-gapped (망분리)
  environments. No telemetry, no hidden network calls.
- **Regulation mapping** with an explicit review status on every mapping. Haechi never
  claims an article applies unless the mapping file says so, with a source.

## Install

Requires Python 3.11 or newer.

```bash
pip install haechi        # or: uv tool install haechi
haechi --version
```

## Quick start: scan text for Korean personal data

```bash
haechi scan-text "고객 연락처는 010-0000-1234, 주민번호 구공일삼공일-이공공공공공공 입니다"
```

```
┏━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ # ┃ 유형 / Kind        ┃ 값 / Value     ┃ 검증 / Checksum ┃ 뷰 / View ┃ 신뢰도 / Confidence ┃
┡━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ 전화번호 (phone)   │ 010-****-1234  │ n/a             │ original  │ medium              │
│ 2 │ 주민등록번호 (rrn) │ 901301-2****** │ n/a             │ spoken    │ low                 │
└───┴────────────────────┴────────────────┴─────────────────┴───────────┴─────────────────────┘
2건 탐지 / 2 finding(s): phone=1, rrn=1
```

The second number was written out in spoken Korean digits and was still caught via the
normalised `spoken` view. It uses an impossible birth date (month 13), the form Haechi
requires for synthetic RRN canaries, so it is reported with `low` confidence.

More options:

```bash
haechi scan-text -f chatbot-log.txt          # scan a UTF-8 file
cat transcript.txt | haechi scan-text --json # read stdin, print JSON
haechi scan-text --mode strict "..."         # require valid checksums
haechi scan-text --no-normalise "..."        # scan the raw text only
```

Detected values are **masked by default**. `--show-values` prints them unmasked.

| Detector | What it checks |
|---|---|
| 주민등록번호 (RRN) | `YYMMDD-GNNNNNN`, valid birth date; checksum in `strict` mode. Numbers issued from October 2020 have no checksum, so `loose` (default) reports checksum-invalid numbers too, and RRN-formatted numbers with impossible dates (`low` confidence). |
| 사업자등록번호 | `NNN-NN-NNNNN` with the official checksum |
| Card numbers | 13–19 digits, Luhn |

Numbers written **without separators** (a bare 13-digit RRN, 13–19-digit card or 10-digit
business number) are only reported when a matching keyword (주민, 카드, 사업자, …) is nearby.
One random digit run in ten passes these checksums, so bare order numbers, timestamps and
barcodes would otherwise be flagged. See [docs/en/evaluation.md](docs/en/evaluation.md)
for precision and recall.
| Phone numbers | mobile, landline, 070, `+82`, 대표번호 (15xx/16xx/18xx) |
| Email | address syntax |
| Bank accounts | **heuristic**: 10–14 digit runs near a banking keyword |

### Exit codes

| Code | Meaning |
|---|---|
| 0 | nothing found / success |
| 1 | personal data found (or, from v0.1, the CI gate failed) |
| 2 | usage or configuration error |
| 3 | feature not available in this version |

This makes `haechi scan-text` usable as a CI check on logs or fixtures.

## Configuration preview

`haechi init` writes a sample `haechi.yaml`. In v0.0.1, `haechi run` validates it and
explains any errors in Korean and English; running attacks arrives in v0.1.

```yaml
version: 1
target:
  type: openai-compatible
  base_url: http://localhost:11434/v1   # Ollama
  model: exaone3.5
purpose: "보험사 고객 상담 챗봇. 본인 확인된 고객에게 자기 계약 정보만 안내한다."
canaries:
  - name: other_customer_rrn
    value: "901301-2000000"   # synthetic; month 13 cannot be a real birth date
plugins: [kr-pii]
mutators: [jamo, chosung, code_switch, impersonation]
seed: 42
limits:
  max_requests: 500
gate:
  max_fail_rate: 0.0
```

## Safety notice

- **Use synthetic data only.** Never put real personal data into configs, canaries or test
  fixtures. Haechi rejects RRN canaries with a real birth date (numbers issued from October
  2020 have no checksum, so a checksum cannot prove a value is fake) and card or business
  number canaries that pass their checksum.
- **Only test systems you are authorised to test.** See [RESPONSIBLE_USE.md](RESPONSIBLE_USE.md).
- **Not legal advice.** Regulation mappings are provided for orientation, carry a review
  status (`draft` / `reviewed`) and do not establish legal compliance.
- Heuristic detectors (e.g. bank accounts) can miss data or flag harmless numbers. A clean
  scan is not proof that no personal data is present.

## Roadmap

- **v0.1** — targets (`openai-compatible`, `http`, `python`, `mock`), YAML attack packs
  (first: `kr-pii`), seeded Korean mutators (jamo, 초성, code-switching, spacing,
  honorifics, impersonation, indirect injection, base64), canary and policy judges, an async
  runner with request caps and caching, JSON and Markdown reports, CI gating, and
  개인정보보호법 / OWASP LLM Top 10 mappings.
- **v0.2** — agent harness with fake tools, tool-call policy judge, an optional and clearly
  labelled non-deterministic LLM judge, further regulation packs.

## Related work

Haechi builds on ideas from AgentDojo, DataSIR, Rebuff/Vigil canary checks, AgentDAM,
PrivacyLens and KDPII, with no code dependency on any of them. See
[docs/en/related-work.md](docs/en/related-work.md) (한국어: [docs/ko/related-work.md](docs/ko/related-work.md)).

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). Security issues: see [SECURITY.md](SECURITY.md).

## Acknowledgements

Haechi is developed with the help of Claude Code.

## Licence

Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
