liveBook · Manning

ChatGPT

As explained in Build Financial Software with Generative AI (From Scratch)

A conversational generative-AI system that responds to natural-language prompts and can generate text or code.

ChatGPT is a conversational generative-AI system that responds to natural-language prompts. In software development, it can help summarize unfamiliar regulations, generate code, and investigate bugs. Its responses can vary even when the same prompt is repeated, so treat them as starting points rather than verified answers. section 1.5.2 section 1.5.3

A useful workflow is to start with a specific request, inspect the result, and refine the prompt. For example, a general summary of Check 21 can be narrowed to its benefits for bank customers or shortened to a few sentences. section 1.5.2

Build and refine a balance display

Ask ChatGPT for Python code that prints “Current Balance: $1000.00.” Then request changes: accept a balance as input, move formatting into a function, add type hints, and return the formatted string instead of printing it inside the function. Review each revision and try it with suitable input. section 1.5.2

Listing 1.4 Returning a string
def print_balance(current_balance: str) -> str:  #1
    """
    Returns the current balance in a formatted string.

    Parameters:
    - current_balance (str): The current balance to be formatted, as a string.

    Returns:                                #2
    - str: The formatted current balance.    #2
    """
    return f"Current Balance: ${float(current_balance):,.2f}" #3

# Ask the user to enter the current balance
user_input = input("Enter current balance: ") #4

# Call the function to get the formatted balance and then print it
formatted_balance = print_balance(user_input)  #5
print(formatted_balance)   #6

The final revision returns the formatted balance so the calling code can print it. section 1.5.2

Investigate a transaction bug

A function intended to retain three recent transactions keeps only two. Asked why the code does not work, ChatGPT identifies the removal condition and suggests avoiding the name max because it shadows a Python built-in. Use the accompanying unit test to check the behavior rather than accepting the explanation alone. section 1.5.3

Listing 1.5 Simple function to store transactions
def last_transactions(user_transactions: list, 
➥transaction: str, max: int = 3) -> list: #1
    """
    Adds a transaction to the list of user transactions 
 ➥and returns the updated list.
    :param max_length: Maximum transactions to keep
    :param user_transactions: List of current transactions
    :param transaction: New transaction
    :return: Updated list of transactions
    """
    if len(user_transactions) + 1 >= max:  #2
        user_transactions.pop(0)            #3

    user_transactions.append(transaction)  #3

    return user_transactions               #4

Inspect the condition that removes a transaction before the new one is appended. section 1.5.3

Generated code also needs domain review. An ACH-file parser generated by ChatGPT 3.5 omitted record types 5 and 8 and mislabeled types 6 and 7. A ChatGPT 4 response included more detail; a follow-up request separated parsing into functions, but those functions still needed implementation and testing with valid and invalid records. section 2.3.1

Check version-specific advice independently. In one historical example, ChatGPT supplied a Python PostgreSQL example using psycopg2 but did not recognize psycopg3 because its information was out of date. Even a plausible revision based on an assumption needs verification against the intended library and version. section 1.5.7

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Works through prompt refinement, generated code, and debugging, without explaining model internals.
Examples
Uses Check 21 summaries, a Python balance display, a transaction-retention bug, and an ACH parser.
What it assumes
Assumes general software-development experience while introducing simple Python through prompts.
What you can do after
Apply ChatGPT to refine prompts, generate and investigate code, and review results with tests and domain knowledge.
How it connects
Connects ChatGPT with prompt engineering, unit testing, ACH file parsing, and software versioning.

Also explained in

Compare how 21 books explain ChatGPT →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.