Turns out defaultdict and str.format(**d) don't work well together; using string.Formatter().vformat() instead. My bad.