Architect expression regex for phone formatting failing on nulls

Trying to format inbound caller ID from +1XXXXXXXXXX to (XXX) XXX-XXXX in Architect using a script data action. The regex replace works in the sandbox but crashes the flow if the number is missing. Current expression: if(contains($input.Phone,"+1"),replace($input.Phone,"\\+1([0-9]{3})([0-9]{3})([0-9]{4})","(\\1) \\2-\\3"),"N/A"). The JSON payload shows null instead of empty string causing the script to abort. How to handle the null check properly?