Concepts / Maintaining Data Structural Integrity

Maintaining Data Structural Integrity

Text is inherently unstructured, so data placed in a text-based model's context loses its layout unless structure is maintained deliberately.

  • Programming

Why Text Loses Layout

Imagine you are building an AI agent that searches for potential sales leads. You give it a table of prices or leads that looks neat on your screen, with names in one column, companies in another, and deal stages in a third. To a human reader, the table is organized. To the model inside the agent, that table is not a table at all unless the structure survives the trip into the model's context.

Many AI agents are built around a text-based model. Everything the model works with arrives as text inside its context, and that text carries no built-in layout. A list of sales leads, a table of prices, or a set of ordered steps may look organized to a human reader, but once it is written into the context, the model receives a stream of characters. The organization you intended has to survive that trip, and it does not always do so. This lesson follows that trip step by step and shows where the structure goes missing and how it can be protected.

Structure Lives Outside the Text

Definition

Data structural integrity refers to keeping the structure of data intact as it is used, especially when that data is unstructured or text-based. Because text is inherently unstructured, the data stored in the context of a text-based model is unstructured too, so structure has to be maintained deliberately rather than assumed.

The key idea is that a table's structure is not a property of the characters themselves. Rows, columns, and the grouping of values into records are relationships that a human reader sees on the page. When the table is converted into text, those relationships must be re-created by whoever reads the text. For a text-based model, that means the model has to infer them.

Row 1: Name,Company, Stageheader rowOne flat charactersequenceno row or column boundariesRow 2: Ana,Brightwave, Contacteddata rowRow 3: Ben,Northwind, Newdata rowwritten into context
How does a two-dimensional table look to a human compared with the single flat character sequence the model receives, and what information is lost in that conversion?

The before side of the diagram is what you see; the after side is what the model is given. Nothing in the flat sequence says that a particular word is a header or that two values belong to the same lead. The rows are still present as text, but the column boundaries and the grouping are gone unless they are described in the text itself.

Tracing a Lead Table into Context

The source describes a concrete sequence. You start with a structured object that has rows and columns. To use it, you write its contents into the context line by line. At that point the table has become a sequence of text lines. The rows are still there, but the columns, the grouping of values into records, and the idea that the lines belong together are all things the model must infer from the text. The diagram below traces that path.

Structured tablerows and columnsWrite contents lineby lineeach row becomes a lineText lines in contextcolumns and grouping notexplicitModel infersstructureinference, not a guaranteeserializeenter contextread
When a table is pasted into a model's context, at which step do its rows, columns, and cell boundaries disappear, and what does the model actually receive at the end?
Worked example

Following One Lead Through the Pipeline

An agent has a table with a header row (Name, Company, Stage) and a lead row (Ana, Brightwave, Contacted). The table is written into the context line by line. What does the model have to work out for itself?

  1. 1
    Start with the structured object

    The table has three columns and at least two rows, and each value sits in a known cell.

  2. 2
    Write it into the context

    The contents are written out line by line, so the lead row becomes a line of text such as Ana Brightwave Contacted.

  3. 3
    Check what survived

    The line still contains the three values, but nothing marks where the Name cell ends and the Company cell begins.

  4. 4
    Identify what must be inferred

    The model must infer that the first value is a name, that the three values form one record, and that the first line is a header describing the columns below it.

Result

The model receives text that can be read as a table, but it has to guess that it is one. The values are all present; the structure is only implied.

Locating a Cell in Flattened Text

A useful way to see the risk is to ask where a single value lands when a table is flattened. Suppose the table has three rows, the first being a header, and three columns. If you read the cells in order from left to right and top to bottom, each cell gets a position in the linear text. The diagram lists those positions and the value found at each one.

Row 1, Col 1NameRow 1, Col 2CompanyRow 1, Col 3StageRow 2, Col 1AnaRow 2, Col 2BrightwaveRow 2, Col 3ContactedRow 3, Col 1BenRow 3, Col 2NorthwindRow 3, Col 3New
If a value sits in row 2, column 3 of a table, where does that value land in the linear text, and how can the model lose track of which column it belongs to?

The value Contacted, located in row 2 and column 3, lands at position 5 of the flattened sequence. Nine cells become one long run of text, and the column a value belongs to is determined only by counting positions. When the header row is far away from the data or the cells are separated by ordinary spaces, that counting becomes unreliable, and a value can easily be attached to the wrong column in the reader's mind.

Memory Systems That Keep Fields Attached

The source offers a remedy: give the agent a memory system capable of storing structured data. Structured data kept in such a system does not have to be flattened into lines of text and then reconstructed by the model. The system holds the structure itself. An agent asked to find potential sales leads can use an Excel sheet to store the leads it finds, so each lead stays in an organized form that the agent can return to.

FeatureFree text in the context windowStructured memory such as a spreadsheet
How a lead is heldAs a line of charactersAs labeled fields in a record
Which column a value belongs toMust be inferred by the readerStored with the value itself
Returning to a recordRequires finding and re-reading the textThe record can be retrieved in its organized form
Risk to structureLayout lost when the text is writtenStructure kept by the system

Keeping the same sales lead data as free text versus as structured records

Keeping Actions in Order with a Queue

Structure is not only about tables. An agent also has to keep track of a sequence of actions that must be performed in a particular order. The source gives a queue as the tool for this job: the agent can use a queue to store the sequence of actions to be performed. A queue keeps items in the order they were added and hands them back in that same order, so the sequence the agent planned is the sequence it follows.

Agentplans the stepsQueueholds planned actionsadd: search for leadsadd: draft outreachadd: log resultsremove: search for leadsremove: draft outreachremove: log results
When actions are added to and removed from a queue, in what order do they come out?

What do you think happens?

Three actions are added to a queue in the order A, B, C. They are then removed one at a time with nothing else happening in between. In what order do they come out?

  • C, B, A

  • A, B, C

  • B, A, C

  • The order is random

Reveal answer
Answer:

A, B, C

A queue keeps items in the order they were added and hands them back in that same order. The first action added is the first one performed, so the planned sequence is followed exactly.

Mistakes That Break Structure

  • Common mistake

    Assuming that a table written line by line is understood as a table

    What it looks like

    Pasting each row of a lead table into the context and expecting the model to know which value is the company.

    Why it fails

    Feeding a table into context line by line does not guarantee the model understands that the lines form a table. The column boundaries are no longer explicit.

    Do this instead

    Keep the structure in a memory system that stores the records as labeled fields, or describe the fields explicitly in the text.

  • Common mistake

    Treating a flattened table as if its positions still show columns

    What it looks like

    Counting words in a flat line to decide which column a value is in, when a value or a space is out of place.

    Why it fails

    Once the table is flattened, a column is only implied by counting positions, which breaks easily when the layout is irregular.

    Do this instead

    Store the values as fields with explicit names so the column is recorded with the value.

  • Common mistake

    Assuming that a list of planned steps stays in order without a mechanism for it

    What it looks like

    Writing three planned actions into free text and assuming the agent will perform them in the order they appear.

    Why it fails

    Order is a property the agent has to keep track of. Nothing in plain text guarantees that the planned sequence is followed.

    Do this instead

    Store the sequence of actions in a queue, which keeps items in the order they were added and returns them in that same order.

Protecting a Lead Table Yourself

MEDIUM

An agent must work with a table of five sales leads, each with a name, a company, a deal stage, and a follow-up date. Describe how you would keep the structure of this data intact as the agent works, and name the part of the workflow that should hold the leads and the part that should hold the planned follow-up actions.

Hints
  • Ask what happens to the column boundaries when the table is written into the context line by line.
  • Consider which structure a memory system can hold for each lead, and why it helps to return to a lead in its organized form.
  • Think about the planned follow-up actions as a sequence that must run in a specific order.

Key Takeaways

  • Text is inherently unstructured, so a table written into a text-based model's context loses its layout unless the structure is maintained deliberately.
  • Writing a table line by line leaves the rows in place but makes the columns and record groupings something the model must infer, and inference is not a guarantee.
  • A memory system that stores structured data, such as an Excel sheet, keeps each lead in an organized form so the agent can return to it without rebuilding the structure from text.
  • A queue keeps a sequence of actions in the order they were added and returns them in that same order, which is the right tool when planned order must be preserved.

More concepts starting with M