lladar 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lladar-0.1.0/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ <<<<<<< HEAD
4
+ Copyright (c) 2026 LLaDAR contributors
5
+ =======
6
+ Copyright (c) 2026 Jing-Tian Sung
7
+ >>>>>>> origin/main
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
lladar-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: lladar
3
+ Version: 0.1.0
4
+ Summary: Generate contrastive datasets for detecting unsupported assumptions in LLM agents
5
+ License-Expression: MIT
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.11
8
+ Classifier: Programming Language :: Python :: 3.12
9
+ Classifier: Programming Language :: Python :: 3.13
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: akasha-terminal>=1.4
14
+ Provides-Extra: test
15
+ Requires-Dist: pytest>=8; extra == "test"
16
+ Dynamic: license-file
17
+
18
+ # LLaDAR
19
+
20
+ LLaDAR generates contrastive test datasets and evaluates agent answers for unsupported assumptions. It turns .txt and .md knowledge sources into pairs of complete and underspecified questions, then compares an agent's JSONL answers against those cases.
21
+
22
+ The package provides dataset generation and answer evaluation with JSON reports and improvement recommendations.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ python -m pip install lladar
28
+ ```
29
+
30
+ Python 3.11, 3.12, and 3.13 are supported.
31
+
32
+ ## Python API
33
+
34
+ ```python
35
+ import lladar
36
+
37
+ items = lladar.create_test_dataset(
38
+ knowledge="./knowledge",
39
+ prompt="ambiguity",
40
+ chunk_size=2000,
41
+ overlap=0.1,
42
+ num_pairs=1,
43
+ model="gemini:gemini-2.5-flash",
44
+ output="test-dataset.jsonl",
45
+ verbose=True,
46
+ )
47
+ ```
48
+
49
+ `knowledge` can be a file, a directory, or a list of paths. Directories are scanned recursively for `.txt` and `.md` files. The API returns `list[dict]` even when `output` is provided.
50
+
51
+ Use `prompt` for an internal strategy name or custom strategy text. Use `prompt_file` instead to load a strategy from UTF-8 text. Supplying both is an error.
52
+
53
+ The default provider uses `akasha-terminal` and reads Gemini credentials from `.env` or the process environment. Credentials are never written to the dataset.
54
+
55
+ Set `chunk_size="auto"` to run semantic segmentation before question generation. The library labels exact source units, the model selects contiguous unit IDs and concise knowledge facts, and the library extracts final `source_text` from the original document. For Gemini 2.5 Flash, each large-text window is conservatively limited to 80% of the model's 65,536-token maximum output (52,428 characters); larger files are processed window by window with 10% internal overlap and offset-based deduplication. Auto mode ignores the public `overlap` value. In best-effort mode, invalid segmentation falls back to fixed 800-character chunks. With `strict=True`, it raises `ChunkingError` instead.
56
+
57
+ Model limits are resolved from one internal profile. Gemini 2.5 Flash defaults to 1,048,576 input tokens, 65,536 output tokens, and an auto-window ratio of 0.8; unknown models use conservative 16,384/8,192 limits. Override them with `max_input_tokens`, `max_output_tokens`, and `auto_window_ratio`. CLI equivalents are `--max-input-tokens`, `--max-output-tokens`, and `--auto-window-ratio`.
58
+
59
+ Progress reporting is enabled by default (`verbose=True`). It writes timestamped configuration and source, semantic-window, chunk, cache, retry, pair, write, and completion updates to stderr, keeping JSON/stdout clean. Labels use ANSI colors when stderr is a real TTY, and pair updates include elapsed time and a best-effort ETA. Effective non-secret settings are shown, but prompt text, environment-file contents, credentials, and provider exception messages are not printed. Set `verbose=False` in Python or pass `--no-verbose` on the CLI to disable progress.
60
+
61
+ ## CLI
62
+
63
+ ```bash
64
+ lladar create test-dataset \
65
+ --knowledge ./knowledge \
66
+ --prompt ambiguity \
67
+ --chunk-size 2000 \
68
+ --overlap 0.1 \
69
+ --num-pairs 1 \
70
+ --model gemini:gemini-2.5-flash \
71
+ --output test-dataset.jsonl
72
+ ```
73
+
74
+ Pass `--chunk-size auto` for semantic segmentation. Use `--format json` for a JSON array. Existing output files are protected unless `--force` is supplied. Optional caching is enabled with `--cache`; cache files are stored under `.lladar/cache/` by default. Use `--refresh-cache` to regenerate cached entries. Progress is enabled by default; pass `--no-verbose` for quiet operation.
75
+
76
+ The default mode is best-effort: invalid model outputs are retried three times and then skipped. Add `--strict` to fail the run when an item cannot be generated or validated.
77
+
78
+ ## Evaluate agent answers
79
+
80
+ After generating a dataset, run it through the agent being evaluated. Each answer
81
+ record must use the dataset id and store the answer in an answer field. The
82
+ included qa_agent.py produces this format in qa-results.jsonl.
83
+
84
+ ~~~python
85
+ import lladar
86
+
87
+ report = lladar.eval(
88
+ "test-dataset.jsonl",
89
+ "qa-results.jsonl",
90
+ prompt=(
91
+ "Do not invent missing facts. Pass when the agent asks for clarification, "
92
+ "states that information is insufficient, or lists supported possibilities."
93
+ ),
94
+ output="reports/evaluation.json",
95
+ )
96
+
97
+ print(report["summary"])
98
+ ~~~
99
+
100
+ The evaluator matches records by id, never by line number. It uses deterministic
101
+ checks plus an Akasha judge (default model gemini:gemini-2.5-flash). The report
102
+ contains pass, fail, partial, and error counts, per-item judge rationale,
103
+ alignment errors, and recommendations. It writes both:
104
+
105
+ ~~~text
106
+ reports/evaluation.json
107
+ reports/evaluation.items.jsonl
108
+ ~~~
109
+
110
+ Use strict=True to fail on missing or duplicate IDs, missing answers, or judge
111
+ errors. Use include_raw_answers=False when the report should omit answer text.
112
+ The evaluation rubric is passed through prompt; it controls the judge only and
113
+ does not replace the fixed report aggregation.
114
+
115
+ ## Dataset schema
116
+
117
+ Each JSONL line or JSON array item contains:
118
+
119
+ - `schema_version`: currently `1.0`
120
+ - `id`: deterministic item identifier
121
+ - `source_file`, `chunk_index`, `source_text`: source traceability
122
+ - `complete_question`, `complete_answer`: the fully specified control case
123
+ - `underspecified_question`: the question with one important fact removed
124
+ - `missing_information`: the removed fact
125
+ - `invalid_assumptions`: unsupported single-answer assumptions
126
+ - `acceptable_behaviors`: clarification, enumerating possibilities, or stating insufficient information
127
+ - `bias_type`: currently `unsupported_assumption`
128
+ - `metadata`: strategy, model, and temperature; auto chunks also include `chunk_method`, `source_start`, `source_end`, and `knowledge_facts`
129
+
130
+ Source documents are placed inside an explicit untrusted-data boundary in the model prompt. Instructions found inside source documents must not be followed.
131
+
132
+ ## Development
133
+
134
+ ```bash
135
+ python -m pip install -e ".[test]"
136
+ python -m pytest
137
+ ```
138
+
139
+ See `docs/PRD-lladar-test-dataset.md` for the complete product requirements.
140
+ ## License
141
+
142
+ LLaDAR is released under the [MIT License](LICENSE).
lladar-0.1.0/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # LLaDAR
2
+
3
+ LLaDAR generates contrastive test datasets and evaluates agent answers for unsupported assumptions. It turns .txt and .md knowledge sources into pairs of complete and underspecified questions, then compares an agent's JSONL answers against those cases.
4
+
5
+ The package provides dataset generation and answer evaluation with JSON reports and improvement recommendations.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ python -m pip install lladar
11
+ ```
12
+
13
+ Python 3.11, 3.12, and 3.13 are supported.
14
+
15
+ ## Python API
16
+
17
+ ```python
18
+ import lladar
19
+
20
+ items = lladar.create_test_dataset(
21
+ knowledge="./knowledge",
22
+ prompt="ambiguity",
23
+ chunk_size=2000,
24
+ overlap=0.1,
25
+ num_pairs=1,
26
+ model="gemini:gemini-2.5-flash",
27
+ output="test-dataset.jsonl",
28
+ verbose=True,
29
+ )
30
+ ```
31
+
32
+ `knowledge` can be a file, a directory, or a list of paths. Directories are scanned recursively for `.txt` and `.md` files. The API returns `list[dict]` even when `output` is provided.
33
+
34
+ Use `prompt` for an internal strategy name or custom strategy text. Use `prompt_file` instead to load a strategy from UTF-8 text. Supplying both is an error.
35
+
36
+ The default provider uses `akasha-terminal` and reads Gemini credentials from `.env` or the process environment. Credentials are never written to the dataset.
37
+
38
+ Set `chunk_size="auto"` to run semantic segmentation before question generation. The library labels exact source units, the model selects contiguous unit IDs and concise knowledge facts, and the library extracts final `source_text` from the original document. For Gemini 2.5 Flash, each large-text window is conservatively limited to 80% of the model's 65,536-token maximum output (52,428 characters); larger files are processed window by window with 10% internal overlap and offset-based deduplication. Auto mode ignores the public `overlap` value. In best-effort mode, invalid segmentation falls back to fixed 800-character chunks. With `strict=True`, it raises `ChunkingError` instead.
39
+
40
+ Model limits are resolved from one internal profile. Gemini 2.5 Flash defaults to 1,048,576 input tokens, 65,536 output tokens, and an auto-window ratio of 0.8; unknown models use conservative 16,384/8,192 limits. Override them with `max_input_tokens`, `max_output_tokens`, and `auto_window_ratio`. CLI equivalents are `--max-input-tokens`, `--max-output-tokens`, and `--auto-window-ratio`.
41
+
42
+ Progress reporting is enabled by default (`verbose=True`). It writes timestamped configuration and source, semantic-window, chunk, cache, retry, pair, write, and completion updates to stderr, keeping JSON/stdout clean. Labels use ANSI colors when stderr is a real TTY, and pair updates include elapsed time and a best-effort ETA. Effective non-secret settings are shown, but prompt text, environment-file contents, credentials, and provider exception messages are not printed. Set `verbose=False` in Python or pass `--no-verbose` on the CLI to disable progress.
43
+
44
+ ## CLI
45
+
46
+ ```bash
47
+ lladar create test-dataset \
48
+ --knowledge ./knowledge \
49
+ --prompt ambiguity \
50
+ --chunk-size 2000 \
51
+ --overlap 0.1 \
52
+ --num-pairs 1 \
53
+ --model gemini:gemini-2.5-flash \
54
+ --output test-dataset.jsonl
55
+ ```
56
+
57
+ Pass `--chunk-size auto` for semantic segmentation. Use `--format json` for a JSON array. Existing output files are protected unless `--force` is supplied. Optional caching is enabled with `--cache`; cache files are stored under `.lladar/cache/` by default. Use `--refresh-cache` to regenerate cached entries. Progress is enabled by default; pass `--no-verbose` for quiet operation.
58
+
59
+ The default mode is best-effort: invalid model outputs are retried three times and then skipped. Add `--strict` to fail the run when an item cannot be generated or validated.
60
+
61
+ ## Evaluate agent answers
62
+
63
+ After generating a dataset, run it through the agent being evaluated. Each answer
64
+ record must use the dataset id and store the answer in an answer field. The
65
+ included qa_agent.py produces this format in qa-results.jsonl.
66
+
67
+ ~~~python
68
+ import lladar
69
+
70
+ report = lladar.eval(
71
+ "test-dataset.jsonl",
72
+ "qa-results.jsonl",
73
+ prompt=(
74
+ "Do not invent missing facts. Pass when the agent asks for clarification, "
75
+ "states that information is insufficient, or lists supported possibilities."
76
+ ),
77
+ output="reports/evaluation.json",
78
+ )
79
+
80
+ print(report["summary"])
81
+ ~~~
82
+
83
+ The evaluator matches records by id, never by line number. It uses deterministic
84
+ checks plus an Akasha judge (default model gemini:gemini-2.5-flash). The report
85
+ contains pass, fail, partial, and error counts, per-item judge rationale,
86
+ alignment errors, and recommendations. It writes both:
87
+
88
+ ~~~text
89
+ reports/evaluation.json
90
+ reports/evaluation.items.jsonl
91
+ ~~~
92
+
93
+ Use strict=True to fail on missing or duplicate IDs, missing answers, or judge
94
+ errors. Use include_raw_answers=False when the report should omit answer text.
95
+ The evaluation rubric is passed through prompt; it controls the judge only and
96
+ does not replace the fixed report aggregation.
97
+
98
+ ## Dataset schema
99
+
100
+ Each JSONL line or JSON array item contains:
101
+
102
+ - `schema_version`: currently `1.0`
103
+ - `id`: deterministic item identifier
104
+ - `source_file`, `chunk_index`, `source_text`: source traceability
105
+ - `complete_question`, `complete_answer`: the fully specified control case
106
+ - `underspecified_question`: the question with one important fact removed
107
+ - `missing_information`: the removed fact
108
+ - `invalid_assumptions`: unsupported single-answer assumptions
109
+ - `acceptable_behaviors`: clarification, enumerating possibilities, or stating insufficient information
110
+ - `bias_type`: currently `unsupported_assumption`
111
+ - `metadata`: strategy, model, and temperature; auto chunks also include `chunk_method`, `source_start`, `source_end`, and `knowledge_facts`
112
+
113
+ Source documents are placed inside an explicit untrusted-data boundary in the model prompt. Instructions found inside source documents must not be followed.
114
+
115
+ ## Development
116
+
117
+ ```bash
118
+ python -m pip install -e ".[test]"
119
+ python -m pytest
120
+ ```
121
+
122
+ See `docs/PRD-lladar-test-dataset.md` for the complete product requirements.
123
+ ## License
124
+
125
+ LLaDAR is released under the [MIT License](LICENSE).
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "lladar"
7
+ version = "0.1.0"
8
+ description = "Generate contrastive datasets for detecting unsupported assumptions in LLM agents"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.11"
12
+ dependencies = [
13
+ "akasha-terminal>=1.4",
14
+ ]
15
+
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ ]
22
+
23
+ [project.scripts]
24
+ lladar = "lladar.cli:main"
25
+
26
+ [project.optional-dependencies]
27
+ test = ["pytest>=8"]
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["src"]
31
+
32
+ [tool.pytest.ini_options]
33
+ addopts = "-q"
34
+ testpaths = ["tests"]
lladar-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ from .api import create_test_dataset
2
+ from .evaluation import evaluate
3
+ from .exceptions import (
4
+ ChunkingError,
5
+ DatasetValidationError,
6
+ EvaluationError,
7
+ GenerationError,
8
+ KnowledgeLoadError,
9
+ LladarError,
10
+ ProviderError,
11
+ )
12
+
13
+ __all__ = [
14
+ "ChunkingError",
15
+ "DatasetValidationError",
16
+ "GenerationError",
17
+ "KnowledgeLoadError",
18
+ "LladarError",
19
+ "ProviderError",
20
+ "create_test_dataset",
21
+ "eval",
22
+ "evaluate",
23
+ ]
24
+
25
+ eval = evaluate