llm_attribute_extractor
Four-step SNOMED CT attribute extraction pipeline.
Public API
extract_attributes(source_term, attribute_searcher, ...) → dict
Helpers handle individual steps
infer_attributes — Step 2 (LLM infers attribute mentions) _retrieve_candidates — Step 3 (embed mentions, retrieve SNOMED candidates) _build_selection_prompt — Step 4 (build LLM selection prompt)
ContentFilterError
Bases: Exception
Raised when the LLM content filter blocks a response.
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
65 66 | |
assign_role_groups(result, hierarchy_settings)
Group the selected attributes with the cached MRCM rules (in place); no-op when grouping is disabled.
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
588 589 590 591 592 593 | |
call_llm(system_prompt, user_prompt)
Call the LLM and return LlmResult(content, cost_usd).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_prompt
|
str
|
System-level prompt text. |
required |
user_prompt
|
str
|
User-level prompt text. |
required |
Returns:
| Type | Description |
|---|---|
LlmResult
|
LlmResult(content, cost). |
Raises:
| Type | Description |
|---|---|
ContentFilterError
|
If the content filter blocks the response. |
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
drop_non_candidate_values(result, candidates)
Remove selected concepts that were not offered as candidates for their attribute (in place).
The selection prompt only allows candidates, but the LLM can copy a concept from the reference
examples instead. Such values are removed from attributes, llm_role_groups and
role_groups, and recorded in result["dropped_selections"].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
dict
|
Pipeline result with the selected concepts. |
required |
candidates
|
DataFrame | list[dict]
|
The retrieved candidates ( |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
The dropped values as |
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
extract_attributes(source_term, attribute_searcher, reference_searcher, hierarchy_settings=None)
Run the 4-step SNOMED CT attribute extraction pipeline.
Steps
- Retrieve reference examples (similar SNOMED concepts and their attributes).
- LLM infers applicable attributes.
- Retrieve SNOMED candidate values per attribute.
- LLM selects exact SNOMED concepts from candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_term
|
str
|
The clinical term to decompose. |
required |
attribute_searcher
|
AttributeSearcher
|
|
required |
reference_searcher
|
ReferenceSearcher
|
|
required |
hierarchy_settings
|
HierarchySettings | None
|
Pipeline configuration. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys |
dict
|
|
dict
|
|
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
format_reference_examples(similar_terms, hierarchy_settings, include_concept_ids=False)
Format reference examples into a human-readable block for the prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
similar_terms
|
list[dict]
|
List of reference dicts from the reference searcher. |
required |
hierarchy_settings
|
HierarchySettings
|
Pipeline configuration; |
required |
include_concept_ids
|
Append concept IDs to terms and attribute values. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string, or empty string if no terms. |
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
infer_attributes(source_term, reference_examples, hierarchy_settings)
Step 2: Use the LLM to infer applicable SNOMED attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_term
|
str
|
Term to decompose. |
required |
reference_examples
|
List
|
Reference examples. |
required |
hierarchy_settings
|
HierarchySettings
|
Pipeline configuration. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Dict, float]
|
ExtractionResult(components, cost). |
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
parse_json_response(response)
Parse a JSON response from an LLM, stripping markdown fences if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
str
|
Raw LLM response string. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Parsed dict. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the response cannot be parsed as JSON. |
Source code in src/ariadne/hierarchy/llm_attribute_extractor.py
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 | |