def validate_elements(new_elements, known_elements):
    """
    Check new elements (entities or intents) against already identified elements.
    Returns elment list, success_code where
    element list is the bad entities if it failed
    >>> validate_elements([1,2,3], [])
    ([1, 2, 3], True)
    >>> validate_elements([1,2,2], [])
    ([2], False)
    >>> validate_elements([], [])
    ([], True)
    >>> validate_elements([1,2,2], [2])
    ([2], False)
    >>> validate_elements([1,2], [2])
    ([2], False)
    """
    unique_elements = set(new_elements)
    is_unique = sorted(unique_elements) == sorted(new_elements)

    overlap = unique_elements.intersection(known_elements)
    is_known = bool(overlap)

    if not is_unique:
        duplicated_elements = set(
            elem for elem in new_elements if new_elements.count(elem) > 1
        )
        overlap = overlap.union(duplicated_elements)
    failure = is_known or not is_unique
    return (list(overlap if failure else unique_elements), not failure)