def GetDefaultFormat(predictions, key_name='predictions'):
  """Get default output format for prediction results."""
  if not isinstance(predictions, list):
    # This usually indicates some kind of error case, so surface the full API
    # response
    return 'json'
  elif not predictions:
    return None
  # predictions is guaranteed by API contract to be a list of similarly shaped
  # objects, but we don't know ahead of time what those objects look like.
  elif isinstance(predictions[0], dict):
    keys = ', '.join(sorted(predictions[0].keys()))
    return """
          table(
              {}:format="table(
                  {}
              )"
          )""".format(key_name, keys)

  else:
    return 'table[no-heading]({})'.format(key_name)