SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2024.findings-emnlp.504 · EMNLP Findings · 2024

How Far Can In-Context Alignment Go? Exploring the State of In-Context Alignment

Yu Bai, Yang Gao, Yinghao Li, Heyan Huang, Huashan Sun

Open in the Atlas

Code that ran

6 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 1 failure of our instrument; 5 no recorded run), measured 2026-11-24; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2024.findings-emnlp.504.json · badge: /api/ran/2024.findings-emnlp.504.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
Re-Align/URIAL canonical (classifier label)
classifier basis: census
6 ran · 5 no recorded run
FunctionStatusWhere it lives
apply_urial Ran
ran on a synthesized input
Re-Align/URIAL/src/legacy/vllm_infer/vllm_urial.py
code served (permissive licence) · get_code("0cadf76319f5b4fc")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# pure_input_texts: list of strings that will be formatted into prompts
pure_input_texts = [
    "What is the capital of France?",
    "Explain photosynthesis in simple terms."
]

# urial_prompt: a string that serves as the system prompt/instruction
urial_prompt = "You are a helpful AI assistant. Answer the following query."

ARGS = {
    "pure_input_texts": pure_input_texts,
    "urial_prompt": urial_prompt
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
clear_output Ran
ran; our contract draft was wrong, not the code
Re-Align/URIAL/src/unified_utils.py
code served (permissive licence) · get_code("484169aa666774ae")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

ARGS = {
    "output": "Here is some code:\n```python\nprint('hello')\n```\nAnd some <|endoftext|> text.",
    "model_name": "gpt2",
    "urial": True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
openai_chat_request Ran
ran on a synthesized input
Re-Align/URIAL/evaluate/eval_utils.py
code served (permissive licence) · get_code("a9d15e4437a4a672")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import openai
from unittest.mock import MagicMock, patch

# Mock the OpenAI API response
def mock_chat_completion_create(**kwargs):
    return {
        'choices': [
            {
                'finish_reason': 'stop',
                'message': {'content': 'This is a mock response from OpenAI.'}
            },
            {
                'finish_reason': 'length',
                'message': {'content': 'This is another mock response.'}
            }
        ]
    }

# Patch the openai.ChatCompletion.create method
openai.ChatCompletion.create = MagicMock(side_effect=mock_chat_completion_create)

ARGS = {
    'model': 'gpt-3.5-turbo',
    'engine': 'text-davinci-003',
    'temperature': 0.7,
    'max_tokens': 512,
    'top_p': 0.95,
    'frequency_penalty': 0.1,
    'presence_penalty': 0.2,
    'prompt': 'What is the capital of France?',
    'n': 2,
    'messages': None,
    'stop': ['\n', 'END']
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
preprocess Ran
ran on a synthesized input
Re-Align/URIAL/src/legacy/adapt_utils.py
code served (permissive licence) · get_code("5600790ea64fbfcf")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import json
import os
import tempfile

class Args:
    def __init__(self):
        self.adapt_mode = 'zero_shot'
        self.model_name = 'gpt2'
        self.system_msg = 'default'
        self.eof_strings = ''
        self.retrieve_data_path = 'none'
        self.num_demos = 2
        self.urial_prefix_path = None
        self.adapt_ckpt = None

# Create temporary files for testing file-based adapt modes
temp_dir = tempfile.mkdtemp()

# Create a urial prefix file
urial_file = os.path.join(temp_dir, 'urial_prefix.txt')
with open(urial_file, 'w') as f:
    f.write('You are a helpful assistant.')

# Create a style prefix file
style_file = os.path.join(temp_dir, 'style_prefix.txt')
with open(style_file, 'w') as f:
    f.write('## Query 0\n\n```\nExample query\n```\n\n## Initial Answer 0\n\n```\nExample answer\n```\n\n## Revised Answer 0\n\n```')

# Create retrieve data file
retrieve_file = os.path.join(temp_dir, 'retrieve_data.json')
retrieve_data_content = [
    {
        'instruction': 'What is the capital of France?',
        'pure_input': 'What is the capital of France?',
        'output': ['Paris is the capital of France.'],
        'rex': [
            {
                'instruction': 'What is the capital of Germany?',
                'input': '',
                'output': 'Berlin is the capital of Germany.'
            }
        ]
    }
]
with open(retrieve_file, 'w') as f:
    json.dump(retrieve_data_content, f)

# Create args for different test cases
args_zero_shot = Args()
args_zero_shot.adapt_mode = 'zero_shot'
args_zero_shot.model_name = 'gpt2'

args_llama = Args()
args_llama.adapt_mode = None
args_llama.model_name = 'chat-llama-7b'
args_llama.system_msg = 'default'

args_vicuna = Args()
args_vicuna.adapt_mode = None
args_vicuna.model_name = 'vicuna-7b'
args_vicuna.system_msg = 'default'

args_urial = Args()
args_urial.adapt_mode = 'urial'
args_urial.urial_prefix_path = urial_file

args_restyle = Args()
args_restyle.adapt_mode = 'restyle'
args_restyle.retrieve_data_path = retrieve_file
args_restyle.adapt_ckpt = style_file

args_retrieve = Args()
args_retrieve.adapt_mode = 'retrieve'
args_retrieve.retrieve_data_path = retrieve_file
args_retrieve.num_demos = 2

# Use the simplest case for the main test
ARGS = {
    'in_text': 'What is the capital of France?',
    'ind': 0,
    'args': args_zero_shot
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
retry_handler Ran
ran on a synthesized input
Re-Align/URIAL/evaluate/eval_utils.py
code served (permissive licence) · get_code("2a55bf45c6775c40")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import sys
import time
from functools import wraps

# Minimal stand-in for openai.error classes
class RateLimitError(Exception):
    pass

class APIError(Exception):
    pass

# Create a mock openai module structure
class MockOpenAIError:
    RateLimitError = RateLimitError
    APIError = APIError

sys.modules['openai'] = type(sys)('openai')
sys.modules['openai'].error = MockOpenAIError()

# Now define the function
def retry_handler(retry_limit=10):
    """
        This is an error handler for requests to OpenAI API.
        If will retry for the request for `retry_limit` times if the error is not a rate limit error.
        Otherwise, it will wait for the time specified in the error message and constantly retry.
        You can add specific processing logic for different types of errors here.

        Args:
            retry_limit (int, optional): The number of times to retry. Defaults to 3.
        
        Usage:
            @retry_handler(retry_limit=3)
            def call_openai_api():
                pass
    """

    def decorate(func):

        @wraps(func)
        def wrapper(*args, **kwargs):
            retried = 0
            while True:
                try:
                    sys.stdout.flush()
                    return func(*args, **kwargs)
                except Exception as e:
                    if isinstance(e, RateLimitError):
                        words = str(e).split(' ')
                        try:
                            time_to_wait = int(words[words.index('after') + 1])
                        except ValueError:
                            time_to_wait = 5
                        time.sleep(time_to_wait)
                    elif isinstance(e, APIError):
                        print('API error:', str(e))
                        if 'Invalid' in str(e):
                            print('Invalid request, returning.')
                            raise e
                    else:
                        print(e.__class__.__name__ + ':', str(e))
                        if retried < retry_limit:
                            print(f'Retrying for the {retried + 1} time..')
                        else:
                            print('Retry limit reached. Saving the error message and returning.')
                            print(kwargs['prompt'])
                            raise e
                        retried += 1
        return wrapper
    return decorate

# Define test function that uses the decorator
@retry_handler(retry_limit=3)
def sample_api_call(prompt="test"):
    return "success"

# Construct ARGS dict
ARGS = {
    'retry_limit': 5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
shorten Ran
ran on a synthesized input
Re-Align/URIAL/src/legacy/adapt_utils.py
code served (permissive licence) · get_code("9943cfb44feb60a9")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def shorten(s, n=300):
    ws = s.split(' ')
    if len(ws) <= n:
        return s
    else:
        return ' '.join(ws[:n]) + ' ... '

# Test case 1: string with fewer words than n
s1 = "This is a short string with only a few words"

# Test case 2: string with more words than n (using default n=300)
s2 = " ".join(["word"] * 400)

ARGS = {
    "s": s1,
    "n": 300
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_conv_template Not yet run
unverified (harvested, no recorded run)
Re-Align/URIAL/src/fastchat_conversation.py
code served (permissive licence) · get_code("86b180ae170d46ff")
How it ran

no invocation recorded.

load_eval_data Not yet run
unverified (harvested, no recorded run)
Re-Align/URIAL/src/legacy/vllm_infer/vllm_urial.py
code served (permissive licence) · get_code("5307f9cdcc42a778")
How it ran

no invocation recorded.

load_urial_prompt Not yet run
unverified (harvested, no recorded run)
Re-Align/URIAL/src/legacy/vllm_infer/vllm_urial.py
code served (permissive licence) · get_code("ccf694a5437a3734")
How it ran

no invocation recorded.

map_to_conv Not yet run
unverified (harvested, no recorded run)
Re-Align/URIAL/src/fastchat_conversation.py
code served (permissive licence) · get_code("2b125d345c32713c")
How it ran

no invocation recorded.

postprocess Not yet run
unverified (harvested, no recorded run)
Re-Align/URIAL/src/legacy/adapt_utils.py
code served (permissive licence) · get_code("f3aee0ed0da4c633")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 5 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 1 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_conv_template 69 other papers
14 dated earlier, 18 later, 36 same year, order not determinable, 1 undated
1911.03705 (2019-11)
CommonGen: A Constrained Text Generation Challenge for Generative Commonsense Reasoning
2112.05682 (2021-12)
Self-attention Does Not Need $O(n^2)$ Memory
2204.07705 (2022-04)
SUPER-NATURALINSTRUCTIONS: Generalization via Declarative Instructions on 1600+ NLP Tasks
and 66 more not named here
openai_chat_request 2 other papers
2 dated earlier
1911.03705 (2019-11)
CommonGen: A Constrained Text Generation Challenge for Generative Commonsense Reasoning
2305.17390 (2023-05)
SWIFTSAGE: A Generative Agent with Fast and Slow Thinking for Complex Interactive Tasks
retry_handler 2 other papers
2 dated earlier
1911.03705 (2019-11)
CommonGen: A Constrained Text Generation Challenge for Generative Commonsense Reasoning
2305.17390 (2023-05)
SWIFTSAGE: A Generative Agent with Fast and Slow Thinking for Complex Interactive Tasks
clear_output 1 other paper
1 same year, order not determinable
2405.19874 (2024-05)
Is In-Context Learning Sufficient for Instruction Following in LLMs?
map_to_conv 1 other paper
1 same year, order not determinable
2405.19874 (2024-05)
Is In-Context Learning Sufficient for Instruction Following in LLMs?

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Recent studies have demonstrated that In-Context Learning (ICL), through the use of specific demonstrations, can align Large Language Models (LLMs) with human preferences known as In-Context Alignment (ICA), indicating that models can comprehend human instructions without requiring parameter adjustments. However, the exploration of the mechanism and applicability of ICA remains limited. In this paper, we begin by dividing the context text used in ICA into three categories: format, system prompt, and example. Through ablation experiments, we investigate the effectiveness of each part in enabling ICA to function effectively. We then examine how variants in these parts impact the model's alignment performance. Our findings indicate that the example part is crucial for enhancing the model's alignment capabilities, with changes in examples significantly affecting alignment performance. We also conduct a comprehensive evaluation of ICA's zero-shot capabilities in various alignment tasks. The results indicate that compared to parameter fine-tuning methods, ICA demonstrates superior performance in knowledge-based tasks and tool-use tasks. However, it still exhibits certain limitations in areas such as multi-turn dialogues and instruction following. Source codes and scripts are available at https://github.com/ li-aolong/how-far-can-ica-go.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2024.findings-emnlp.504")
get_code_for_paper("2024.findings-emnlp.504")
have("2024.findings-emnlp.504")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2024.findings-emnlp.504.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2024.findings-emnlp.504.svg)](https://syntology.ai/paper/2024.findings-emnlp.504)

Connect an agent — have() is free.