Ai knowledge and logicHelpers

is_holiday

Check if a date is a public holiday in a given country.

is_holiday(country: str, state: str = None, region: str = None, check_date: str = None) -> dict

Checks whether a given date is a public holiday in a specific country, with optional state/region filtering.


Parameters

NameTypeDescription
countrystrISO 3166-1 alpha-2 country code (e.g., "US", "DE", "GR")
statestr or NoneOptional state or province code (e.g., "CA", "BY")
regionstr or NoneOptional region code for more specific subdivision
check_datestr or NoneDate to check in YYYY-MM-DD format. Defaults to today if omitted

Returns

{
    "isHoliday": bool,
    "holidays": [{"name": str, "type": str}]  # list of holidays on that date
}

The holidays list is empty when isHoliday is False.


Examples

Adjust response based on holidays

def execute_action(context):
    result = is_holiday("DE", state="BY")

    if result["isHoliday"]:
        holiday_name = result["holidays"][0]["name"]
        return {
            "message": f"Today is {holiday_name} — our warehouse is closed. "
                       "Orders placed today will ship on the next business day."
        }

    return {"message": "Your order will ship today."}

Check a specific date

def execute_action(context):
    delivery_date = context["args"]["deliveryDate"]
    result = is_holiday("US", check_date=delivery_date)

    if result["isHoliday"]:
        return {
            "warning": f"Delivery is scheduled on a holiday ({result['holidays'][0]['name']}). "
                       "It may be delayed by one business day."
        }

    return {"deliveryDate": delivery_date, "onSchedule": True}

On this page