diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7143c90c58a7d6e7b2328569deae0f11fff86ad..4af548cdb8abc60b2084123cc230038bd5c3f8ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
 
 * Fixed issue with certain multi value fields on the filter configuration of a data source.
 * Fixed issue with navigation menu.
+* Make the 'Display the groups of a contact' output format resilient against empty inputs.
 
 # Version 1.115
 
diff --git a/Civi/DataProcessor/FieldOutputHandler/GroupsOfContactFieldOutputHandler.php b/Civi/DataProcessor/FieldOutputHandler/GroupsOfContactFieldOutputHandler.php
index 856670e9a7235672be6115cea9ccfd8ac5b17f1e..72d385461614f5c2d68fe2013249129a7b4c3ec7 100644
--- a/Civi/DataProcessor/FieldOutputHandler/GroupsOfContactFieldOutputHandler.php
+++ b/Civi/DataProcessor/FieldOutputHandler/GroupsOfContactFieldOutputHandler.php
@@ -6,11 +6,11 @@
 
 namespace Civi\DataProcessor\FieldOutputHandler;
 
+use Civi\DataProcessor\FieldOutputHandler\FieldOutput;
 use Civi\DataProcessor\ProcessorType\AbstractProcessorType;
 use CRM_Dataprocessor_ExtensionUtil as E;
 use Civi\DataProcessor\Source\SourceInterface;
 use Civi\DataProcessor\DataSpecification\FieldSpecification;
-use Civi\DataProcessor\FieldOutputHandler\FieldOutput;
 use Civi\DataProcessor\Exception\DataSourceNotFoundException;
 use Civi\DataProcessor\Exception\FieldNotFoundException;
 
@@ -66,7 +66,7 @@ class GroupsOfContactFieldOutputHandler extends AbstractFieldOutputHandler {
    * @param \Civi\DataProcessor\ProcessorType\AbstractProcessorType $processorType
    */
   public function initialize($alias, $title, $configuration) {
-    list($this->contactIdSource, $this->contactIdField) = $this->initializeField($configuration['field'], $configuration['datasource'], $alias);
+    [$this->contactIdSource, $this->contactIdField] = $this->initializeField($configuration['field'], $configuration['datasource'], $alias);
     $this->outputFieldSpecification = new FieldSpecification($this->contactIdField->name, 'String', $title, null, $alias);
     if (isset($configuration['parent_group']) && $configuration['parent_group']) {
       $this->parent_group_id = civicrm_api3('Group', 'getvalue', array('return' => 'id', 'name' => $configuration['parent_group']));
@@ -83,29 +83,35 @@ class GroupsOfContactFieldOutputHandler extends AbstractFieldOutputHandler {
    */
   public function formatField($rawRecord, $formattedRecord) {
     $contactId = $rawRecord[$this->contactIdField->alias];
-    $sql = "SELECT g.title, g.id
+    if ($contactId) {
+      $sql = "SELECT g.title, g.id
             FROM civicrm_group g
             INNER JOIN civicrm_group_contact gc ON gc.group_id = g.id
             WHERE gc.status = 'Added' AND gc.contact_id = %1";
-    if ($this->parent_group_id) {
-      $childGroupIds = \CRM_Contact_BAO_GroupNesting::getDescendentGroupIds([$this->parent_group_id], FALSE);
-      $sql .= " AND gc.group_id IN (".implode(", ", $childGroupIds).")";
-    }
-    $sql .= " ORDER BY g.title";
-    $sqlParams[1] = array($contactId, 'Integer');
-    $dao = \CRM_Core_DAO::executeQuery($sql, $sqlParams);
-    $rawValues = array();
-    $formattedValues = array();
-    while($dao->fetch()) {
-      $rawValues[] = array(
-        'group_id' => $dao->id,
-        'group' => $dao->title,
-      );
-      $formattedValues[] = $dao->title;
+      if ($this->parent_group_id) {
+        $childGroupIds = \CRM_Contact_BAO_GroupNesting::getDescendentGroupIds([$this->parent_group_id], FALSE);
+        $sql .= " AND gc.group_id IN (" . implode(", ", $childGroupIds) . ")";
+      }
+      $sql .= " ORDER BY g.title";
+      $sqlParams[1] = [$contactId, 'Integer'];
+      $dao = \CRM_Core_DAO::executeQuery($sql, $sqlParams);
+      $rawValues = [];
+      $formattedValues = [];
+      while ($dao->fetch()) {
+        $rawValues[] = [
+          'group_id' => $dao->id,
+          'group' => $dao->title,
+        ];
+        $formattedValues[] = $dao->title;
+      }
+      $output = new FieldOutput($rawValues);
+      $output->formattedValue = implode(", ", $formattedValues);
+      return $output;
+    } else {
+      // no contact id, show no groups.
+      return new FieldOutput();
     }
-    $output = new FieldOutput($rawValues);
-    $output->formattedValue = implode(", ", $formattedValues);
-    return $output;
+
   }
 
   /**
@@ -175,7 +181,7 @@ class GroupsOfContactFieldOutputHandler extends AbstractFieldOutputHandler {
    * @return array
    */
   public function processConfiguration($submittedValues) {
-    list($datasource, $field) = explode('::', $submittedValues['contact_id_field'], 2);
+    [$datasource, $field] = explode('::', $submittedValues['contact_id_field'], 2);
     $configuration['field'] = $field;
     $configuration['datasource'] = $datasource;
     $configuration['parent_group'] = isset($submittedValues['parent_group']) ? $submittedValues['parent_group'] : false;