Skip to content

Commit eec57e3

Browse files
author
Bob Strahan
committed
Apply assessment enable property to granular assessment
1 parent edfe986 commit eec57e3

File tree

7 files changed

+49
-40
lines changed

7 files changed

+49
-40
lines changed

CHANGELOG.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,18 @@ SPDX-License-Identifier: MIT-0
2020
- **Cost Optimization**: When disabled, no LLM API calls or S3 operations are performed
2121
- **Configuration Example**: Set `assessment.enabled: false` to disable, `enabled: true` to enable (default)
2222

23-
### Changed
24-
- **State Machine Simplification**: Removed `SummarizationChoice` and `AssessmentChoice` conditional states from all patterns (Pattern 2, 3) for cleaner workflows
25-
- **Service Logic Enhancement**: SummarizationService and AssessmentService now check configuration `enabled` flag at the beginning of processing methods
26-
- **Configuration Schema Updates**: Added `enabled` boolean property to summarization and assessment sections in all CloudFormation template schemas
27-
- Updated all sample configurations to include `summarization.enabled: true` and `assessment.enabled: true`
28-
- Updated configuration documentation with new summarization and assessment control approaches
29-
3023
### Removed
3124
- **CloudFormation Parameters**: Removed `IsSummarizationEnabled` and `IsAssessmentEnabled` parameters from all pattern templates
3225
- **Related Conditions**: Removed parameter conditions and state machine definition substitutions for both features
3326
- **Conditional Logic**: Eliminated complex conditional logic from state machine definitions for summarization and assessment steps
3427

35-
### Fixed
36-
- **CloudFormation Template Deployment Error**: Fixed "Template format error: Unresolved resource dependencies [IsAssessmentEnabled]" by removing final parameter reference in main template PATTERN3STACK parameters
37-
- **State Machine Logic**: Simplified conditional assessment/summarization steps that were causing complex workflow logic
38-
- **Parameter Dependencies**: Cleaned up all CloudFormation parameter dependencies and references
39-
40-
### Documentation
41-
- **Updated Documentation**: Enhanced docs/configuration.md, docs/architecture.md, and all pattern-specific docs (pattern-1.md, pattern-2.md, pattern-3.md)
42-
- **Service Documentation**: Updated lib/idp_common_pkg/idp_common/summarization/README.md with configuration examples and behavior details
43-
- **Migration Guidance**: Added migration notes about the CloudFormation parameter removal
28+
### ⚠️ Breaking Changes
29+
- **Configuration Migration Required**: When updating a stack that previously had `IsSummarizationEnabled` or `IsAssessmentEnabled` set to `false`, these features will now default to `enabled: true` after the update. To maintain the disabled behavior:
30+
1. Update your configuration file to set `summarization.enabled: false` and/or `assessment.enabled: false` as needed
31+
2. Save the configuration changes immediately after the stack update
32+
3. This ensures continued cost optimization by preventing unexpected LLM API calls
33+
- **Action Required**: Review your current CloudFormation parameter settings before updating and update your configuration accordingly to preserve existing behavior
34+
4435

4536
## [0.3.11]
4637

lib/idp_common_pkg/idp_common/assessment/__init__.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import logging
1616
from typing import Any, Dict
1717

18+
from idp_common.utils import normalize_boolean_value
19+
1820
from .granular_service import GranularAssessmentService
1921
from .models import AssessmentResult, AttributeAssessment
2022
from .service import AssessmentService as OriginalAssessmentService
@@ -58,24 +60,6 @@ def _format_attribute_descriptions(self, attributes):
5860
return self._service._format_attribute_descriptions(attributes)
5961

6062

61-
def _normalize_boolean_value(value: Any) -> bool:
62-
"""
63-
Normalize a value to a boolean, handling string representations.
64-
65-
Args:
66-
value: Value to normalize (can be bool, str, or other)
67-
68-
Returns:
69-
Boolean value
70-
"""
71-
if isinstance(value, bool):
72-
return value
73-
elif isinstance(value, str):
74-
return value.lower() in ("true", "1", "yes", "on")
75-
else:
76-
return bool(value)
77-
78-
7963
def create_assessment_service(region: str = None, config: Dict[str, Any] = None):
8064
"""
8165
Factory function to create the appropriate assessment service based on configuration.
@@ -97,7 +81,7 @@ def create_assessment_service(region: str = None, config: Dict[str, Any] = None)
9781
granular_enabled_raw = granular_config.get("enabled", False)
9882

9983
# Normalize the enabled value to handle both boolean and string values
100-
granular_enabled = _normalize_boolean_value(granular_enabled_raw)
84+
granular_enabled = normalize_boolean_value(granular_enabled_raw)
10185

10286
logger.info(
10387
f"Granular assessment enabled check: raw_value={granular_enabled_raw} (type: {type(granular_enabled_raw)}), normalized={granular_enabled}"

lib/idp_common_pkg/idp_common/assessment/granular_service.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,15 @@ def process_document_section(self, document: Document, section_id: str) -> Docum
998998
Returns:
999999
Document: Updated Document object with assessment results appended to extraction results
10001000
"""
1001+
# Check if assessment is enabled in configuration
1002+
assessment_config = self.config.get("assessment", {})
1003+
from idp_common.utils import normalize_boolean_value
1004+
1005+
enabled = normalize_boolean_value(assessment_config.get("enabled", True))
1006+
if not enabled:
1007+
logger.info("Assessment is disabled via configuration")
1008+
return document
1009+
10011010
# Validate input document
10021011
if not document:
10031012
logger.error("No document provided")

lib/idp_common_pkg/idp_common/assessment/service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,10 @@ def process_document_section(self, document: Document, section_id: str) -> Docum
600600
"""
601601
# Check if assessment is enabled in configuration
602602
assessment_config = self.config.get("assessment", {})
603-
if not assessment_config.get("enabled", True):
603+
from idp_common.utils import normalize_boolean_value
604+
605+
enabled = normalize_boolean_value(assessment_config.get("enabled", True))
606+
if not enabled:
604607
logger.info("Assessment is disabled via configuration")
605608
return document
606609

lib/idp_common_pkg/idp_common/summarization/service.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,10 @@ def process_document(
395395
"""
396396
# Check if summarization is enabled in configuration
397397
summarization_config = self.config.get("summarization", {})
398-
if not summarization_config.get(
399-
"enabled", True
400-
): # Default to True for backward compatibility
398+
from idp_common.utils import normalize_boolean_value
399+
400+
enabled = normalize_boolean_value(summarization_config.get("enabled", True))
401+
if not enabled:
401402
logger.info(
402403
f"Summarization is disabled in configuration for document {document.id}, skipping processing"
403404
)

lib/idp_common_pkg/idp_common/utils/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,28 @@ def extract_json_from_text(text: str) -> str:
235235
return text
236236

237237

238+
def normalize_boolean_value(value: Any) -> bool:
239+
"""
240+
Normalize a value to a boolean, handling string representations.
241+
242+
This function is useful for configuration values that may come as strings
243+
(e.g., from JSON config files or environment variables) but need to be
244+
treated as booleans.
245+
246+
Args:
247+
value: Value to normalize (can be bool, str, or other)
248+
249+
Returns:
250+
Boolean value
251+
"""
252+
if isinstance(value, bool):
253+
return value
254+
elif isinstance(value, str):
255+
return value.lower() in ("true", "1", "yes", "on")
256+
else:
257+
return bool(value)
258+
259+
238260
def extract_yaml_from_text(text: str) -> str:
239261
"""
240262
Extract YAML string from LLM response text with robust multi-strategy handling.

lib/idp_common_pkg/tests/unit/assessment/test_assessment_enabled_property.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def setUp(self):
3737
classification="Invoice",
3838
page_ids=["1"],
3939
extraction_result_uri="s3://test-bucket/test-doc/extraction-1.json",
40-
status=Status.COMPLETED,
4140
)
4241
],
4342
status=Status.EXTRACTING,

0 commit comments

Comments
 (0)