@@ -118,6 +118,10 @@ def _document_to_update_input(self, document: Document) -> Dict[str, Any]:
118118 "ImageUri" : page .image_uri or "" ,
119119 "TextUri" : page .parsed_text_uri or page .raw_text_uri or "" ,
120120 "TextConfidenceUri" : page .text_confidence_uri or "" ,
121+ # Convert confidence to float if it's a Decimal
122+ "Confidence" : float (page .confidence )
123+ if page .confidence is not None
124+ else 0.0 ,
121125 }
122126 pages_data .append (page_data )
123127
@@ -143,16 +147,28 @@ def _document_to_update_input(self, document: Document) -> Dict[str, Any]:
143147 "PageIds" : page_ids ,
144148 "Class" : section .classification ,
145149 "OutputJSONUri" : section .extraction_result_uri or "" ,
150+ # Convert confidence to float if it's a Decimal
151+ "Confidence" : float (section .confidence )
152+ if section .confidence is not None
153+ else 1.0 ,
146154 }
147155
148156 # Convert confidence threshold alerts
149157 if section .confidence_threshold_alerts :
150158 alerts_data = []
151159 for alert in section .confidence_threshold_alerts :
160+ # Convert Decimal values to string to avoid serialization issues
161+ confidence_value = alert .get ("confidence" )
162+ confidence_threshold_value = alert .get ("confidence_threshold" )
163+
152164 alert_data = {
153165 "attributeName" : alert .get ("attribute_name" ),
154- "confidence" : alert .get ("confidence" ),
155- "confidenceThreshold" : alert .get ("confidence_threshold" ),
166+ "confidence" : float (confidence_value )
167+ if confidence_value is not None
168+ else None ,
169+ "confidenceThreshold" : float (confidence_threshold_value )
170+ if confidence_threshold_value is not None
171+ else None ,
156172 }
157173 alerts_data .append (alert_data )
158174 section_data ["ConfidenceThresholdAlerts" ] = alerts_data
0 commit comments