Skip to content

fix: Psl entity score#619

Merged
Avijit-Microsoft merged 4 commits into
devfrom
psl-entity-score
Jun 16, 2026
Merged

fix: Psl entity score#619
Avijit-Microsoft merged 4 commits into
devfrom
psl-entity-score

Conversation

@Prachig-Microsoft

Copy link
Copy Markdown
Contributor

This pull request overhauls the way extraction quality scores (entity_score and schema_score) are derived, stored, and displayed throughout the content processing pipeline. The main improvement is a new, robust scoring logic that ensures all completed runs yield meaningful numeric scores: using probabilistic confidence when available, and falling back to a structural completeness ratio otherwise. Failed or empty extractions consistently yield 0.0. The changes also update API and UI code to clarify score semantics and handle edge cases gracefully. Comprehensive unit tests are included for the new logic.

Scoring logic improvements:

  • Refactored score calculation in SaveHandler to always emit numeric scores for completed runs: uses probabilistic confidence if available, otherwise falls back to a structural completeness ratio; failed/empty runs yield 0.0. Added _derive_aggregate_scores and _is_filled_value helpers for robust computation. [1] [2]
  • Updated score assignment in find_process_result to use the new aggregate scoring logic.
  • Added comprehensive unit tests for the new scoring logic in test_save_handler_scores.py.

API and model documentation:

  • Clarified the meaning and fallback behavior of entity_score and schema_score in API models (claim_process.py in both API and workflow repositories). [1] [2]

UI and workflow robustness:

  • Updated the web UI (ProcessQueueGrid.tsx) to handle null or undefined scores gracefully, always displaying 0 if the score is missing. [1] [2]
  • Improved workflow step (document_process_executor.py) to robustly coerce score payloads to floats, defaulting to 0.0 on errors or missing values. [1] [2]
  • Minor: Updated score field comments and test coverage for default behaviors. [1] [2]## Purpose
  • ...

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

…ores

Root cause: When the evaluate step couldn't compute any per-field confidence (e.g.
logprobs unavailable on reasoning models like gpt-5/o1/o3, or image-only flow with
no Content Understanding signal), save_handler emitted entity_score=0.0,
schema_score=0.0. These `0.0`s flowed through Cosmos -> API -> UI and rendered as
`0%` (red), indistinguishable from a genuine zero confidence.

Fix: Treat `total_evaluated_fields_count == 0` (or no comparison items) as
*unavailable* and propagate `None` through the ContentProcessor, ContentProcessorAPI
and ContentProcessorWorkflow models. The frontend percentage cell renderer now shows
`N/A` for null/undefined and `0%` only for a genuine numeric zero.

Files changed:
- ContentProcessor: save_handler.py (extracted _derive_aggregate_scores helper)
- ContentProcessor: content_process.py default scores -> None
- ContentProcessorAPI: ContentProcess + Content_Process default scores -> None
- ContentProcessorWorkflow: ContentProcessRecord + Content_Process default scores -> None
- ContentProcessorWorkflow: document_process_executor preserves None instead of
  coercing to 0.0
- ContentProcessorWeb: ProcessQueueGridTypes types scores nullable;
  ProcessQueueGrid passes undefined for null/undefined; CustomCellRender renders
  `N/A` when valueText is null/undefined and only `...` while still processing

Tests:
- New: ContentProcessor/tests/unit/pipeline/test_save_handler_scores.py (5 cases:
  valid scores, missing per-field signal, no comparison items, genuine zero,
  all-fields-above-threshold)
- Updated existing default-value tests in Workflow + src/tests to assert None
- Added tests for explicit zero preservation and Failed status -> None
Per feedback: Completed runs must always show a meaningful number; Failed runs and genuine zeros stay at 0%.

- save_handler._derive_aggregate_scores picks the best available signal: (1) probabilistic confidence when logprobs available; (2) structural completeness (filled fields / total) when no logprobs (reasoning models, image-only flow); (3) 0.0 when no extraction data at all.

- _is_filled_value heuristic: None/empty/whitespace count as not filled; descends into nested dicts/lists.

- Reverted models from Optional[float]=None back to default 0.0.

- Reverted frontend: no N/A path; renders 0% for null/missing scores.

- 15 new tests covering all 3 paths + _is_filled_value heuristic.
…ation

- F401: drop unused sync DefaultAzureCredential import in 3 credential util files (sync flow now raises RuntimeError; AsyncDefaultAzureCredential is still used).

- W293/E122: fix blank-line whitespace and continuation-line indentation in ContentProcessorWorkflow/src/utils/credential_util.py.
@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report •
FileStmtsMissCoverMissing
libs/utils
   azure_credential_utils.py970100% 
TOTAL121716186% 

Tests Skipped Failures Errors Time
244 0 💤 0 ❌ 0 🔥 4.250s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates how extraction quality scores (entity_score / schema_score) are computed and propagated across the pipeline, API models, and UI so that completed runs consistently yield numeric scores (with structural fallback when probabilistic confidence is unavailable) and failures/empty results stay at 0.0.

Changes:

  • Refactors SaveHandler scoring to derive aggregate scores via probabilistic confidence when available, otherwise structural completeness.
  • Hardens workflow/UI score handling to avoid missing/invalid score payloads (defaulting to 0.0/"0").
  • Adds/updates unit tests to cover default score behavior and the new scoring paths.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/ContentProcessor/src/libs/pipeline/handlers/save_handler.py Introduces _derive_aggregate_scores and _is_filled_value and wires derived scores into persisted ContentProcess.
src/ContentProcessor/tests/unit/pipeline/test_save_handler_scores.py Adds unit tests covering probabilistic scoring, structural fallback, and “real zero” behavior.
src/ContentProcessorAPI/app/routers/models/contentprocessor/claim_process.py Updates API model field descriptions to clarify score semantics and fallback behavior.
src/ContentProcessorWorkflow/src/repositories/model/claim_process.py Updates workflow-side model documentation for entity_score / schema_score.
src/ContentProcessorWorkflow/src/steps/document_process/executor/document_process_executor.py Coerces score payloads robustly to floats, defaulting to 0.0 on missing/invalid values.
src/ContentProcessorWeb/src/Pages/DefaultPage/Components/ProcessQueueGrid/ProcessQueueGrid.tsx Updates UI rendering to handle missing scores (fallback display to 0).
src/ContentProcessorWeb/src/Pages/DefaultPage/Components/ProcessQueueGrid/ProcessQueueGridTypes.ts Tweaks UI type documentation wording for entity_score.
src/ContentProcessorWorkflow/src/utils/credential_util.py Minor formatting change and error/log messaging near credential selection failure.
src/ContentProcessor/src/libs/utils/credential_util.py Removes unused DefaultAzureCredential import (sync path).
src/ContentProcessor/src/libs/utils/azure_credential_utils.py Removes unused DefaultAzureCredential import (sync path).
src/tests/ContentProcessorWorkflow/services/test_content_process_models.py Adds assertions/comments reinforcing default scores remain 0.0.
src/tests/ContentProcessorWorkflow/repositories/test_claim_process_model.py Adds assertions/comments reinforcing default scores remain 0.0.
src/ContentProcessorWorkflow/tests/unit/services/test_content_process_models.py Adds unit test ensuring explicit 0.0 scores are preserved.
src/ContentProcessorWorkflow/tests/unit/repositories/test_claim_process_model.py Adds tests ensuring explicit 0.0 scores are preserved and failed runs keep defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ContentProcessor/src/libs/pipeline/handlers/save_handler.py
Comment thread src/ContentProcessor/src/libs/pipeline/handlers/save_handler.py
Comment thread src/ContentProcessorWorkflow/src/utils/credential_util.py
Comment thread src/ContentProcessor/src/libs/utils/credential_util.py
Comment thread src/ContentProcessor/src/libs/utils/azure_credential_utils.py
@Avijit-Microsoft Avijit-Microsoft merged commit 1fee0b1 into dev Jun 16, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants