Skip to content

Conversation

ZeeshanZulfiqarAli
Copy link
Contributor

This PR adds extracted data validation based on the provided schema using Zod. Any offending entry will be replaced by the default value or null in absence of a default value in schema.

Example response:

{
  "completionTime": 27770,
  "extracted": {
    "line_items": [
      {
        "page": 1,
        "value": [
          {
            "line_no": "1",
            "begin_tran_date": "05/05/2023",
            "end_tran_date": "06/05/2023",
            "rec_location": "XYZ",
            "del_location": "ABC",
            "rec_zn": "123",
            "end_zn": "D",
            "tt": null,
            "charge_indicator": null,
            "charge_type": null,
            "chg_type_rate": 0.0101,
            "quantity": 1234,
            "amount_due": 0,
            "notes": "XXXXXXX",
            "location_indicator": "AAAAA"
          },
          {
            "line_no": "2",
            "begin_tran_date": "05/05/2023",
            "end_tran_date": "06/05/2023",
            "rec_location": "XYZ",
            "del_location": "ABC",
            "rec_zn": "12",
            "end_zn": "D",
            "tt": null,
            "charge_indicator": null,
            "charge_type": null,
            "chg_type_rate": 0.6,
            "quantity": 111,
            "amount_due": 0,
            "notes": "AAAAA",
            "location_indicator": "AAAAA"
          }
        ]
      }
    ]
  },
  "fileName": "407cd97d051748f2aea1e1306c0254a5",
  "inputTokens": 1525,
  "outputTokens": 674,
  "pages": [],
  "summary": {
    "totalPages": 0,
    "ocr": null,
    "extracted": { "successful": 1, "failed": 0 }
  },
  "validationLog": {
    "extracted": [
      {
        "page": 1,
        "issues": [
          {
            "received": "SRC",
            "code": "invalid_enum_value",
            "options": ["01", "126"],
            "path": ["line_items", 0, "tt"],
            "message": "Invalid enum value. Expected '01' | '126', received 'SRC'"
          },
          {
            "received": "123",
            "code": "invalid_enum_value",
            "options": ["SRC", "STW"],
            "path": ["line_items", 0, "charge_type"],
            "message": "Invalid enum value. Expected 'SRC' | 'STW', received '123'"
          },
          {
            "received": "XYZ",
            "code": "invalid_enum_value",
            "options": ["P", "Q"],
            "path": ["line_items", 0, "charge_indicator"],
            "message": "Invalid enum value. Expected 'P' | 'Q', received 'XYZ'"
          },
          {
            "received": "STW",
            "code": "invalid_enum_value",
            "options": ["01", "126"],
            "path": ["line_items", 1, "tt"],
            "message": "Invalid enum value. Expected '01' | '126', received 'STW'"
          },
          {
            "received": "123",
            "code": "invalid_enum_value",
            "options": ["SRC", "STW"],
            "path": ["line_items", 1, "charge_type"],
            "message": "Invalid enum value. Expected 'SRC' | 'STW', received '123'"
          },
          {
            "received": "Storage With",
            "code": "invalid_enum_value",
            "options": ["P", "Q"],
            "path": ["line_items", 1, "charge_indicator"],
            "message": "Invalid enum value. Expected 'P' | 'Q', received 'Storage With'"
          }
        ]
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant