Need the LLM response in JSON format but the schema isn’t fixed

  Kiến thức lập trình

LLM Response: – 20 reward points for every Rs. 100 spent on birthday

  • 10 reward points for every Rs. 100 spent on dining, groceries, departmental stores, and movies
  • 2 reward points for every Rs. 100 spent on all other retail purchases, except for fuel

Output Format that i need:

{
    "reward_categories": [
        {
            "category": "Birthday Spends",
            "points_per_transaction": 20,
            "details": "20 reward points for every Rs. 100 spent on your birthday*",
            "capped_points": "Reward points earned on birthday spends (one day before, on, and one day after) are capped at 2,000 reward points per calendar year."
        },
        {
            "category": "Dining",
            "points_per_transaction": 10,
            "details": "10 reward points for every Rs. 100 spent on dining"
        },
        {
            "category": "Groceries",
            "points_per_transaction": 10,
            "details": "10 reward points for every Rs. 100 spent on groceries"
        },
        {
            "category": "Departmental Stores",
            "points_per_transaction": 10,
            "details": "10 reward points for every Rs. 100 spent on departmental stores"
        },
        {
            "category": "Movies",
            "points_per_transaction": 10,
            "details": "10 reward points for every Rs. 100 spent on movies"
        },
        {
            "category": "All Other Retail Purchases (Except Fuel)",
            "points_per_transaction": 2,
            "details": "2 reward points for every Rs. 100 spent on all other retail purchases, except for fuel"
        }
    ]
}

We could define a pydantic model, but the number of category isn’t fixed.
I tried to ask for JSON format in the prompt but it is clubbing the categories as per points.

{
    "reward_categories": [
        {
            "category": "Birthday Spends",
            "points_per_transaction": 20,
            "details": "20 reward points for every Rs. 100 spent on your birthday*",
            "capped_points": "Reward points earned on birthday spends (one day before, on, and one day after) are capped at 2,000 reward points per calendar year."
        },
        {
            "category": "Dining, Movies, Groceries, Departmental Stores, Movies",
            "points_per_transaction": 10,
            "details": "10 reward points for every Rs. 100 spent on dining, groceries, departmental stores and movies"
        },
        {
            "category": "All Other Retail Purchases (Except Fuel)",
            "points_per_transaction": 2,
            "details": "2 reward points for every Rs. 100 spent on all other retail purchases, except for fuel"
        }
    ]
}

LEAVE A COMMENT