from typing import Any

def group_rows_by_review_item_with_dedup(
	rows: list[dict[str, Any]],
) -> dict[str, list[dict[str, Any]]]:
	grouped_rows: dict[str, list[dict[str, Any]]] = {}
	seen_original_texts: dict[str, set[Any]] = {}

	for row in rows:
		review_item = row.get("review_item")
		review_item_key = "<None>" if review_item is None else str(review_item).strip()
		if review_item_key not in grouped_rows:
			grouped_rows[review_item_key] = []
			seen_original_texts[review_item_key] = set()

		original_text = row.get("original_text")
		original_text_key = original_text.strip() if isinstance(original_text, str) else original_text
		if original_text_key in seen_original_texts[review_item_key]:
			continue

		seen_original_texts[review_item_key].add(original_text_key)
		grouped_rows[review_item_key].append(row)

	return dict(sorted(grouped_rows.items(), key=lambda item: item[0]))


if __name__ == "__main__":
	rows = [
		{
			"review_item": "合同主体",
            "original_text": "甲方：XXX公司",
        },{
			"review_item": "合同主体",
			"original_text": "甲方：XXX公司"}
    ]
	result = group_rows_by_review_item_with_dedup(rows)
	print(result)