<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_valid_sid_for_chain(pid, sid):
 """Assert that ``sid`` can be assigned to the single object ``pid`` or to the chain to which ``pid`` belongs. - If the chain does not have a SID, the new SID must be previously unused. - If the chain already has a SID, the new SID must match the existing SID. """

    if not d1_gmn.app.did.is_valid_sid_for_chain(pid, sid):
        existing_sid = d1_gmn.app.revision.get_sid_by_pid(pid)
        raise d1_common.types.exceptions.IdentifierNotUnique(
            0,
            'A different SID is already assigned to the revision chain to which '
            'the object being created or updated belongs. A SID cannot be changed '
            'once it has been assigned to a chain. '
            'existing_sid="{}", new_sid="{}", pid="{}"'.format(existing_sid, sid, pid),
        )