Skip to content

Class ZCL_LLM_TOOL_PARSER

AI Generated documentation.

Overview

The class ZCL_LLM_TOOL_PARSER generates JSON schemas from ABAP data structures, enabling structured data validation and tooling integration. It focuses on mapping ABAP types (elementary types, structures, tables) to JSON schema constructs while incorporating metadata like field descriptions and enum values.

Public Methods:

  • zif_llm_tool_parser~parse:
    Main entry point. Converts an ABAP data structure into a JSON schema string. Handles nested structures, tables, type validation, and metadata integration.

Dependencies

  • Exceptions: zcx_llm_validation for error reporting.
  • Type Descriptors: Relies on cl_abap_typedescr, cl_abap_structdescr, cl_abap_tabledescr, and cl_abap_elemdescr for ABAP type introspection.

Details

Schema Generation Flow

Key Implementation Aspects

  1. Type Mapping:
  2. ABAP INT/INT8 → JSON integer
  3. ABAP DECFLOAT → JSON number
  4. ABAP STRING → JSON string
  5. ABAP CHAR1 with boolean context → JSON boolean (validated via type pool checks).

  6. Metadata Integration:

  7. Field descriptions from descriptions are injected into the schema.
  8. Enum values are converted to JSON enum arrays.

  9. Nested Structures:

  10. Nested ABAP structures become JSON object types with properties.
  11. Paths (e.g., field-subfield) are tracked for metadata assignment.

  12. Table Handling:

  13. ABAP tables are mapped to JSON array types.
  14. Supports tables of structures (nested objects) and multi-level nesting.

  15. Validation:

  16. Rejects unsupported types (e.g., type D).
  17. Ensures CHAR1 fields not flagged as booleans throw errors.
  18. Enforces required fields in generated schemas.

  19. Extension Hooks:

  20. Empty pre_*/post_* methods (e.g., pre_object, post_array) allow subclassing for custom logic.

Example Interaction

When processing a table field:

  1. process_table generates an array skeleton.
  2. process_type resolves the line type (e.g., a structure).
  3. process_structure recursively adds properties for each component.
  4. Metadata (descriptions, enums) is injected during field processing.

This ensures complex ABAP data models are accurately represented as JSON schemas for downstream tooling.