is there any way to get the compatibility of VM size to disk so that I can handle it in code and avoid provisioning failures
Basic_A3 is being retired and is also not supported for Premium disks. Please refer to the MS DOC for more details.

Here is the Python code to check the list of available VM SKUs that support Premium disks in a specific region. To check for VM SKUs that support Standard disks, you can change the condition capability['value'] == 'False'
import requests
import json
# Define the Bearer token
bearer_token = ""
# Define the URL and parameters
url = 'https://management.azure.com/subscriptions/SUB_ID/providers/Microsoft.Compute/skus'
params = {
'api-version': '2021-07-01',
'$filter': "location eq 'westus'"
}
# Define the headers, including the Authorization header with the Bearer token
headers = {
'Authorization': f'Bearer {bearer_token}'
}
# Send the GET request with headers
response = requests.get(url, headers=headers, params=params)
# Check if the response is successful
if response.status_code == 200:
data = response.json()
# Filter for virtual machines with PremiumIO capability set to True
virtual_machines_with_premium_io = []
for item in data['value']:
if item['resourceType'] == 'virtualMachines':
capabilities = item.get('capabilities', [])
for capability in capabilities:
if capability['name'] == 'PremiumIO' and capability['value'] == 'True':
virtual_machines_with_premium_io.append(item)
break
# Print the filtered result
print(json.dumps(virtual_machines_with_premium_io, indent=2))
else:
print(f"Failed to retrieve data: {response.status_code}")
Lists all available VM SKUs for the specified region that are supported Premium

You can also check the VM SKUs that are supported for both Premium and Standard disks in the Azure portal.

Reference: Lists all available Resource SKUs for the specified region