From a77e3e757305ea06a2b51b5ee73caa5a2ff8a912 Mon Sep 17 00:00:00 2001 From: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> Date: Thu, 1 Oct 2026 21:45:07 -0400 Subject: [PATCH] Preserve mixed and nested sequences in layout classification Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> --- .../engineering-universal-document-compiler.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engineering/engineering-universal-document-compiler.md b/engineering/engineering-universal-document-compiler.md index 01f2bb6c..113055b0 100644 --- a/engineering/engineering-universal-document-compiler.md +++ b/engineering/engineering-universal-document-compiler.md @@ -191,14 +191,22 @@ export class DataShapeClassifier { if (Array.isArray(data)) { if (data.length === 0) return 'leaf_item'; + // Classify the whole sequence; a first-item guess can hide later content. + // Mixed scalars/mappings and nested sequences need structural rendering. + const allScalars = data.every(item => typeof item !== 'object' || item === null); + const allMappings = data.every(item => + typeof item === 'object' && item !== null && !Array.isArray(item) + ); + if (!allScalars && !allMappings) return 'block_group'; + // Sequence of Scalars - if (typeof data[0] !== 'object' || data[0] === null) { + if (allScalars) { const avgLength = data.reduce((acc, str) => acc + String(str).length, 0) / data.length; return avgLength <= 35 ? 'badge_list' : 'prose_flow'; } // Sequence of Mappings - const records = data.filter(item => typeof item === 'object' && item !== null); + const records = data; // allMappings: every original item participates const uniformity = this.calculateJaccardUniformity(records); if (uniformity >= 0.55) {