Invalid formula string, reload script to run

The FamilyDocument.SetFormula node of this graph gives an “invalid formula string” warning most of the time. If a titleblock instance is selected and the script is run, the resulting formulas are “null”. If the script is reloaded and run again, it (mostly) works.

I have tried Use Levels on the parameterName and formula inputs, and different lacing settings (longest seems to be the most reliable).

Do you all have suggestions for getting this script to run reliably the first time?