> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maximem.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# conversation.context.get_context_for_prompt

> Get compacted context combined with recent un-compacted messages, pre-formatted for LLM prompt injection.

```python theme={null}
await sdk.conversation.context.get_context_for_prompt(
    conversation_id: str,
    style: str = "structured",
) -> ContextForPromptResponse
```

Returns a single `formatted_context` string that stitches together the compacted history with any messages that arrived after the last compaction cutoff. Drop the result straight into your prompt. No further assembly required.

If no compaction has run yet, every recorded message comes back as a recent message, so this method is useful from the very first turn.

### Parameters

<ParamField path="conversation_id" type="str" required={true}>
  The conversation to assemble context for. Must be a valid UUID [registered via `record_message`](/concepts/context-end-to-end#short-term-context).
</ParamField>

<ParamField path="style" type="str" required={false} default="structured">
  Formatting style for the compacted portion:

  * `"structured"`: labelled sections (facts, decisions, preferences, current state)
  * `"narrative"`: prose summary
  * `"bullet_points"`: bulleted list
</ParamField>

### Returns

A `ContextForPromptResponse` ready for prompt injection.

<ResponseField name="formatted_context" type="str | None">The combined compacted + recent context, formatted per `style`. Inject directly into your LLM prompt.</ResponseField>
<ResponseField name="available" type="bool">Whether usable context (compacted or recent) was found.</ResponseField>
<ResponseField name="is_stale" type="bool">Whether the compacted portion is stale relative to newer messages.</ResponseField>
<ResponseField name="compression_ratio" type="float | None">Compression ratio of the compacted portion.</ResponseField>
<ResponseField name="validation_score" type="float | None">Quality validation score of the compacted portion.</ResponseField>
<ResponseField name="compaction_age_seconds" type="int | None">How long ago the compaction completed.</ResponseField>
<ResponseField name="quality_warning" type="bool">True when the compacted portion was flagged for quality concerns.</ResponseField>
<ResponseField name="recent_messages" type="List[Dict[str, Any]]">Raw un-compacted messages since the last compaction. Use if you want to format them yourself.</ResponseField>
<ResponseField name="recent_message_count" type="int">Number of un-compacted messages included.</ResponseField>
<ResponseField name="compacted_message_count" type="int">Number of messages covered by the compacted portion.</ResponseField>
<ResponseField name="total_message_count" type="int">Total messages in the conversation.</ResponseField>

### Example

```python theme={null}
import uuid
from maximem_synap import MaximemSynapSDK

sdk = MaximemSynapSDK(api_key="synap_your_key_here")
await sdk.initialize()

# conversation_id must be a valid UUID; reuse the conversation's id
conversation_id = str(uuid.uuid4())

ctx = await sdk.conversation.context.get_context_for_prompt(
    conversation_id=conversation_id,
    style="structured",
)

system_prompt = f"""You are a helpful assistant.

Conversation context so far:
{ctx.formatted_context or "(no prior context)"}
"""

print(system_prompt)
print(f"Covered {ctx.compacted_message_count} compacted + {ctx.recent_message_count} recent messages.")
```

### Raises

* `AuthenticationError`: when the API key is missing or invalid.
* `NetworkError`: when the SDK cannot reach Synap.

### See also

* [conversation.context.compact](/sdk-reference/conversation-context/compact)
* [conversation.context.get\_compacted](/sdk-reference/conversation-context/get-compacted)
* [conversation.context.get\_compaction\_status](/sdk-reference/conversation-context/get-compaction-status)
* [conversation.context.fetch](/sdk-reference/conversation-context/fetch)
