def default_parse_dynamic_triplets(
    llm_output: str,
) -> List[Tuple[EntityNode, Relation, EntityNode]]:
    """
    Parse the LLM output and convert it into a list of entity-relation-entity triplets.
    This function is flexible and can handle various output formats.

    Args:
        llm_output (str): The output from the LLM, which may be JSON-like or plain text.

    Returns:
        List[Tuple[EntityNode, Relation, EntityNode]]: A list of triplets.

    """
    triplets = []

    try:
        # Attempt to parse the output as JSON
        data = json.loads(llm_output)
        for item in data:
            head = item.get("head")
            head_type = item.get("head_type")
            relation = item.get("relation")
            tail = item.get("tail")
            tail_type = item.get("tail_type")

            if head and head_type and relation and tail and tail_type:
                head_node = EntityNode(name=head, label=head_type)
                tail_node = EntityNode(name=tail, label=tail_type)
                relation_node = Relation(
                    source_id=head_node.id, target_id=tail_node.id, label=relation
                )
                triplets.append((head_node, relation_node, tail_node))

    except json.JSONDecodeError:
        # Flexible pattern to match the key-value pairs for head, head_type, relation, tail, and tail_type
        pattern = r'[\{"\']head[\}"\']\s*:\s*[\{"\'](.*?)[\}"\'],\s*[\{"\']head_type[\}"\']\s*:\s*[\{"\'](.*?)[\}"\'],\s*[\{"\']relation[\}"\']\s*:\s*[\{"\'](.*?)[\}"\'],\s*[\{"\']tail[\}"\']\s*:\s*[\{"\'](.*?)[\}"\'],\s*[\{"\']tail_type[\}"\']\s*:\s*[\{"\'](.*?)[\}"\']'

        # Find all matches in the output
        matches = re.findall(pattern, llm_output)

        for match in matches:
            head, head_type, relation, tail, tail_type = match
            head_node = EntityNode(name=head, label=head_type)
            tail_node = EntityNode(name=tail, label=tail_type)
            relation_node = Relation(
                source_id=head_node.id, target_id=tail_node.id, label=relation
            )
            triplets.append((head_node, relation_node, tail_node))
    return triplets

    Parse the LLM output and convert it into a list of entity-relation-entity triplets.
    This function is flexible and can handle various output formats.

    Args:
        llm_output (str): The output from the LLM, which may be JSON-like or plain text.

    Returns:
        List[Tuple[EntityNode, Relation, EntityNode]]: A list of triplets.

    
llama-index-core/llama_index/core/indices/property_graph/transformations/dynamic_llm.py