Printing fields in theme: Undefined index: safe_value
The problem is with your function, not the template. 

Ideally you should check if the index exists, e.g.

print array_key_exists($format, $field[0]) ? $field[0]["$format"] : '';


or:

print !empty($field[0]["$format"]) ? $field[0]["$format"] : '';


or:

print @$field[0]["$format"] ? $field[0]["$format"] : '';


Alternatively you can ignore the notices in PHP config (php.ini) or in Drupal admin.

Or you can just prefix the field with @ to silence/suppress any errors (usually not recommended), e.g.

print @$field[0]["$format"];