Utils
build_schema_description(schema, header='Feldhinweise und erlaubte Werte (getrennt durch Semikolons):', type_description_prefix='Beschreibung: ', cardinality_prefix='Kardinalität: ', type_prefix='Typ: ', choices_prefix='Zulässige Werte: ', choices_description_prefix='Hinweise zu den Werten: ', component_separator=' | ', choices_separator='; ', indent_step=' ', include_field_descriptions=True, include_type_descriptions=True, indent=0, root_schema=None)
Build a human‑readable summary for a JSON Schema.
Output format:
- Optional first line: "
Cardinality rules: - type=array ⇒ "0..*" - non-array with "default" ⇒ "0..1" - non-array without "default" ⇒ "1"
Type extraction: - Supports inline "type", direct "$ref", and compositions via "allOf"/"anyOf"/"oneOf" - For arrays, type is taken from "items"
Choices extraction: - Supports inline enums, direct "$ref", and compositions via "allOf"/"anyOf"/"oneOf" - For arrays, choices are taken from "items" (including "$ref" or compositions)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Mapping[str, Any]
|
The JSON Schema dictionary to process |
required |
header
|
str | None
|
Header text for field list (only shown at top level, None to omit) |
'Feldhinweise und erlaubte Werte (getrennt durch Semikolons):'
|
type_description_prefix
|
str | None
|
Prefix for type descriptions (descriptions for the overall schema and nested schemas, not field descriptions) |
'Beschreibung: '
|
cardinality_prefix
|
str | None
|
Prefix for cardinality information (None to omit cardinality) |
'Kardinalität: '
|
type_prefix
|
str | None
|
Prefix for type information (None to omit types) |
'Typ: '
|
choices_prefix
|
str | None
|
Prefix for choices value lists (None to omit choices) |
'Zulässige Werte: '
|
choices_description_prefix
|
str | None
|
Prefix for choices descriptions (None to omit choices descriptions) |
'Hinweise zu den Werten: '
|
component_separator
|
str
|
Separator between field components (name, cardinality, type, choices) |
' | '
|
choices_separator
|
str
|
Separator between individual choices values |
'; '
|
indent_step
|
str
|
String used for each indentation level |
' '
|
include_field_descriptions
|
bool
|
Whether to include field/property descriptions in the output |
True
|
include_type_descriptions
|
bool
|
Whether to include schema/type descriptions (top-level and nested) in the output. NOTE: This is deprecated; please set type_description_prefix to None to omit type descriptions instead. |
True
|
indent
|
int
|
Current indentation level (internal, for recursion) |
0
|
root_schema
|
Mapping[str, Any] | None
|
Root schema containing $defs (internal, for recursion) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string summarizing schema structure, fields, and constraints |
Source code in src/kibad_llm/schema/utils.py
212 213 214 215 216 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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
wrap_terminals_with_metadata(schema, metadata_schema, *, content_key=WRAPPED_CONTENT_KEY, content_description=None)
Wrap every terminal field schema (scalars/enums/const, including nullable unions and refs)
into an object containing:
- metadata_schema (default: evidence_anchor: string)
Notes: - Does NOT wrap the root of $defs entries (important for shared enum defs). - DOES wrap terminal fields inside object definitions in $defs. - Returns a deep-copied dict; input is not mutated.
Source code in src/kibad_llm/schema/utils.py
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 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |