def field_lookup(field_string):
  """Find relevant error field for UNIQUE violation in SQL error message."""
  bad_field = 'code'  # assumes this field as a default
  if field_string.startswith('uq_t_'):
    bad_field = 'title'
  elif field_string.endswith('email'):
    bad_field = 'email'
  elif field_string.endswith('title'):
    bad_field = 'title'
  return bad_field