diff --git a/CHANGELOG.md b/CHANGELOG.md
index c953413f22e1ef591ef336e2b40ab7eafe77f125..50c1c55e3e6034205f19cc0f9f43cf73dfad088f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 # Version 1.96 (in development)
 
+* Prevent fatal PHP 8.1 error with CompareFieldFilter.
+
 # Version 1.95
 
 * Added mixin for smarty templates. So it works with CiviCRM 5.69 and newer.
diff --git a/Civi/DataProcessor/FilterHandler/AbstractFilterHandler.php b/Civi/DataProcessor/FilterHandler/AbstractFilterHandler.php
index 964fcd91b6ede7d75acfe399aea29ced0914527d..1901bd134894943bf566e74e68cd2d84e9d04615 100644
--- a/Civi/DataProcessor/FilterHandler/AbstractFilterHandler.php
+++ b/Civi/DataProcessor/FilterHandler/AbstractFilterHandler.php
@@ -10,6 +10,7 @@ use Civi\DataProcessor\DataFlow\CombinedDataFlow\CombinedSqlDataFlow;
 use Civi\DataProcessor\DataFlow\CombinedDataFlow\SubqueryDataFlow;
 use Civi\DataProcessor\DataFlow\SqlDataFlow;
 use Civi\DataProcessor\DataFlow\SqlTableDataFlow;
+use Civi\DataProcessor\DataSpecification\FieldSpecification;
 use Civi\DataProcessor\Exception\FilterRequiredException;
 use Civi\DataProcessor\FilterCollection\FilterCollection;
 use Civi\DataProcessor\ProcessorType\AbstractProcessorType;
@@ -70,7 +71,7 @@ abstract class AbstractFilterHandler {
   /**
    * @return \Civi\DataProcessor\DataSpecification\FieldSpecification
    */
-  abstract public function getFieldSpecification();
+  abstract public function getFieldSpecification(): FieldSpecification;
 
   /**
    * Initialize the filter
diff --git a/Civi/DataProcessor/FilterHandler/CompareFieldFilter.php b/Civi/DataProcessor/FilterHandler/CompareFieldFilter.php
index d17441ad86b68444389fecb30ed6b81f41d08e6c..d653bbbd9522759e27a8f91307a687272e04a1c9 100644
--- a/Civi/DataProcessor/FilterHandler/CompareFieldFilter.php
+++ b/Civi/DataProcessor/FilterHandler/CompareFieldFilter.php
@@ -197,7 +197,7 @@ class CompareFieldFilter extends AbstractFieldFilterHandler {
   /**
    * @return \Civi\DataProcessor\DataSpecification\FieldSpecification
    */
-  public function getFieldSpecification() {
+  public function getFieldSpecification(): FieldSpecification{
     return $this->fieldSpecification;
   }