def METHOD_NAME(entity: dict) -> str:
    # Special behavior for ensemble
    if 'submodels' in entity['args']:
        del entity['args']['submodels']
    for k, v in entity['args'].items():
        if not str(v).startswith('$'):
            if not is_allowed(v):
                raise Exception(f'Invalid value: {v} for arg {k}')
    args = [f'{k}={v}' for k, v in entity['args'].items() if not str(v).startswith('$')]
    for k, v in entity['args'].items():
        if str(v).startswith('$'):
            v = str(v).replace('$', 'self.')
            args.append(f'{k}={v}')
    args = ','.join(args)
    return f"""{entity['module']}({args})"""