LLM Extraction
Isolated structured extraction interface (Extractor protocol), versioned prompt templates with untrusted-data boundaries, and the lean OpenAI-compatible HTTP client.
extract
Isolated narrow LLM structured advisory extraction layer.
ExtractionError
Bases: RuntimeError
Raised when an extractor fails to return a schema-valid advisory.
Extractor
Bases: Protocol
Narrow ~15% structured extraction boundary isolated from deterministic verification.
Implementations convert untrusted :class:RawArticle prose into candidate
:class:ExtractedAdvisory claims with raw version strings and verbatim quotes; all package
resolution, quote verification, and version math occur downstream in :mod:zerobom.verify.
model_name
property
Identifier of the underlying LLM model used for provenance tracking.
prompt_version
property
Version tag of the extraction prompt template.
extract(article, *, known_aliases=())
Extract a candidate :class:ExtractedAdvisory from an ingested article.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
article
|
RawArticle
|
Normalized ingested article to analyze. |
required |
known_aliases
|
Sequence[str]
|
Optional pre-extracted CVE/GHSA identifiers from deterministic stages. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Candidate |
ExtractedAdvisory
|
class: |
Raises:
| Type | Description |
|---|---|
ExtractionError
|
If extraction or schema validation fails after retries. |
Source code in src/zerobom/extract/base.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
OpenAICompatConfig
Bases: StrictModel
Configuration for :class:OpenAICompatExtractor.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
OpenAI-compatible API base URL (e.g., |
model |
str
|
Model identifier sent to |
api_key |
str | None
|
Optional bearer token (redacted from |
temperature |
float
|
Sampling temperature in |
timeout_seconds |
float
|
HTTP request timeout in seconds. |
max_retries |
int
|
Number of schema/JSON correction retries after the initial attempt. |
max_article_chars |
int
|
Character ceiling passed to :func: |
max_tokens |
int
|
Maximum output tokens requested from the completions endpoint. |
use_json_response_format |
bool
|
Whether to send |
from_env()
classmethod
Construct configuration from ZEROBOM_LLM_* (and OPENAI_API_KEY) env vars.
Returns:
| Name | Type | Description |
|---|---|---|
Configured |
OpenAICompatConfig
|
class: |
Source code in src/zerobom/extract/openai_compat.py
84 85 86 87 88 89 90 91 92 93 94 | |
OpenAICompatExtractor(config, *, client=None)
Narrow structured advisory extractor using any OpenAI-compatible HTTP endpoint.
Initialize the OpenAI-compatible HTTP extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
OpenAICompatConfig
|
Endpoint URL, model name, optional API key, and retry configuration. |
required |
client
|
Client | None
|
Optional pre-configured |
None
|
Source code in src/zerobom/extract/openai_compat.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
client
property
Return the underlying httpx.Client instance.
model_name
property
Configured LLM model identifier.
prompt_version
property
Version tag of the extraction prompt template.
close()
Close the internal HTTP client if owned by this instance.
Source code in src/zerobom/extract/openai_compat.py
388 389 390 391 | |
extract(article, *, known_aliases=())
Extract a candidate :class:ExtractedAdvisory with schema-validated retry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
article
|
RawArticle
|
Normalized ingested article to extract claims from. |
required |
known_aliases
|
Sequence[str]
|
Optional pre-extracted CVE/GHSA identifiers from pre-filtering. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
Validated |
ExtractedAdvisory
|
class: |
ExtractedAdvisory
|
|
Raises:
| Type | Description |
|---|---|
ExtractionError
|
On HTTP failure or when JSON/schema validation fails past retries. |
Source code in src/zerobom/extract/openai_compat.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
build_extraction_messages(article, *, max_chars=MAX_ARTICLE_CHARS, candidate_aliases=())
Build OpenAI-compatible chat messages with untrusted-data fencing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
article
|
RawArticle
|
Ingested :class: |
required |
max_chars
|
int
|
Maximum article body character window passed to the LLM. |
MAX_ARTICLE_CHARS
|
candidate_aliases
|
Sequence[str]
|
Optional non-binding candidate advisory IDs detected deterministically in the article (hints only; LLM must omit contrasted/unrelated CVEs). |
()
|
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
Two-element |
Source code in src/zerobom/extract/prompts.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
prepare_article_window(body, *, max_chars=MAX_ARTICLE_CHARS)
Prepare a bounded article window preserving both opening context and bottom tables.
Security writeups commonly summarize affected versions and patches at the bottom of long articles. Retaining a 55% head + 45% tail window preserves both sections within budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
str
|
Full extracted article body text. |
required |
max_chars
|
int
|
Maximum character budget permitted for the prompt payload. |
MAX_ARTICLE_CHARS
|
Returns:
| Type | Description |
|---|---|
str
|
Original |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/zerobom/extract/prompts.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
sanitize_untrusted_delimiter(text)
Neutralize <UNTRUSTED_ARTICLE> tags inside untrusted prose to prevent fence escape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Untrusted article title or body text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Text with delimiter-like tags HTML-escaped. |
Source code in src/zerobom/extract/prompts.py
127 128 129 130 131 132 133 134 135 136 137 138 139 | |